public GeneralResponse EditCampaignAgent(IEnumerable <EditCampaignAgentRequest> requests, Guid ModifiedEmployeeID) { GeneralResponse response = new GeneralResponse(); try { foreach (EditCampaignAgentRequest request in requests) { CampaignAgent campaignAgent = new CampaignAgent(); campaignAgent = _campaignAgentRepository.FindBy(request.ID); campaignAgent.CampaignAgentName = request.CampaignAgentName; campaignAgent.ModifiedEmployee = _employeeRepository.FindBy(ModifiedEmployeeID); campaignAgent.ModifiedDate = PersianDateTime.Now; #region RowVersion - Validation if (campaignAgent.RowVersion != request.RowVersion) { response.ErrorMessages.Add("EditConcurrencyKey"); return(response); } else { campaignAgent.RowVersion += 1; } if (campaignAgent.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in campaignAgent.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } #endregion _campaignAgentRepository.Save(campaignAgent); } _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { response.ErrorMessages.Add(ex.InnerException.Message); } } return(response); }
public GeneralResponse AddCampaignPayment(IEnumerable <AddCampignPaymentRequest> requests, Guid CampaignAgentID, Guid CreateEmployeeID) { GeneralResponse response = new GeneralResponse(); try { CampaignAgent campaignAgent = new CampaignAgent(); campaignAgent = _campaignAgentRepository.FindBy(CampaignAgentID); foreach (var request in requests) { CampaignPayment campaignPayment = new CampaignPayment(); campaignPayment.ID = Guid.NewGuid(); campaignPayment.CreateDate = PersianDateTime.Now; campaignPayment.CreateEmployee = _employeeRepository.FindBy(CreateEmployeeID); campaignPayment.SuctionModeDetail = _suctionModeDetailRepository.FindBy(request.SuctionModeDetailID); campaignPayment.CampaignAgent = _campaignAgentRepository.FindBy(CampaignAgentID); campaignPayment.Amount = request.Amount; campaignPayment.PaymentDate = request.PaymentDate; campaignPayment.Note = request.Note; campaignPayment.RowVersion = 1; campaignAgent.TotalPayment += campaignPayment.Amount; _campaignPaymentRepository.Add(campaignPayment); } _campaignAgentRepository.Save(campaignAgent); _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { response.ErrorMessages.Add(ex.InnerException.Message); } } return(response); }