Base solution for your next web application
Open Closed

IRepository saving Actions don't work Properly #1555


User avatar
0
yonatanyas created

i cant save any data in the db (i can get the data but can't save it back).

tried to debug it but didn't got any exception/errors

service code:

public class CampaignAppService : ICampaignAppService
    {
        //private readonly IRepository<PreSendCampaign, long> _preSendCampaignRepository;
        private readonly ICampiagnRepository _preSendCampaignRepository;

        public CampaignAppService(ICampiagnRepository preSendCampaignRepository)
        {
            _preSendCampaignRepository = preSendCampaignRepository;
        }


        public PreSendCampaign GetPreSendCampaign(int WorkId)
        {
            PreSendCampaign current = null;

            List<PreSendCampaign> listResults = _preSendCampaignRepository. GetAll().Where(i => i.WorkID.Equals(WorkId)).ToList();

            if (listResults != null && listResults.Count > 0)
            {
                current = listResults[0];
            }

            return current;
        }

        public long SetPreSendCampaign(PreSendCampaign newSendCampaign)
        {
            long newId = 0;

            try
            {
                var Created = _preSendCampaignRepository.InsertOrUpdate(newSendCampaign);
                newId = Created.PreSendCampaignID;
            }
            catch(Exception e)
            {

            }

            return newId;
        }

    }

entity example :

[Table(name: "vts_tbPreSendCampaign_Orc")]
    public class PreSendCampaign : Entity<long>
    {
        [Key]
        public long PreSendCampaignID { get; set; }

        public int WorkID { get; set; }

        [Required]
        public string CampaignBody { get; set; }

        [Required]
        [StringLength(50)]
        public string CampaignSender { get; set; }

        [Required]
        [StringLength(50)]
        public string CampaignTitle { get; set; }

        public bool? IsPublishCampaign { get; set; }
    }

context example:

public IDbSet<PopulationSort> vts_tbPopulationSort { get; set; }

2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It's not recommended to use entities for AppService inputs. You can create a Dto for your AppService input and map it to your entity before saving or inserting your entity.

    In order to update an entity, you should first get it from your repository.

  • User Avatar
    0
    yonatanyas created

    <cite>ismcagdas: </cite> Hi,

    It's not recommended to use entities for AppService inputs. You can create a Dto for your AppService input and map it to your entity before saving or inserting your entity.

    In order to update an entity, you should first get it from your repository.

    i have tried also to get the instance and modify it and update and it still not working: for example :

    var item = _prePopulationRepository.Get(id);
    
                item.DerecognisedIndicator = true;
    
                _prePopulationRepository.Update(item);