public void AddExistingValue() { CpeDbContext context = GetDbHelper.GetDbContext(); CustomerPolicyRepository CustomerPolicyRepository = new CustomerPolicyRepository(context); CustomerPolicyModel customerPolicy = new CustomerPolicyModel() { CustomerId = 1, PolicyId = 1 }; CustomerPolicyRepository.Add(customerPolicy); Assert.Fail(); }
public async Task <IHttpActionResult> Create(CustomerPolicyModel entity) { if (!ModelState.IsValid) { StringBuilder modelErrors = GetModelErrors(ModelState); var result = new ResponseEntityVM() { StatusCode = System.Net.HttpStatusCode.BadRequest, Message = modelErrors.ToString() }; return(Result(result)); } return(Result(await Task.FromResult(_service.AssignPolicy(entity)))); }
public int AssignPolicy([FromBody] List <CustomerPolicyViewModel> value) { if (value != null) { var insertItems = value.Where(x => x.Id == 0 && x.IsSelected).ToList(); insertItems.ForEach(x => { CustomerPolicyModel customerPolicy = new CustomerPolicyModel() { CustomerId = x.Customer.Id, PolicyId = x.Policy.Id }; this.CustomerPolicyRepository.Add(customerPolicy); }); var deleteItems = value.Where(y => y.Id != 0 && !y.IsSelected).ToList(); deleteItems.ForEach(x => { this.CustomerPolicyRepository.Delete(x.Id); }); } return(0); }
public ResponseEntityVM AssignPolicy(CustomerPolicyModel entity) { try { var policyAssignedStatus = AssigmentStatusEnum.Assigned.ToString("G"); var codeList = ((List <CodeVM>)_codeService.GetAssignmentStatusCodes().Result).FirstOrDefault(x => x.Code.Equals(policyAssignedStatus)); var associationAlreadyExists = _repository.FindBy(x => x.CustomerID.Equals(entity.CustomerID) && x.PolicyID.Equals(entity.PolicyID) && x.StatusID.Equals(codeList.CodeID)).ToList(); if (associationAlreadyExists.Count > 0) { return new ResponseEntityVM() { StatusCode = System.Net.HttpStatusCode.Conflict, Message = "The customer already has the policy associated." } } ; entity.StatusID = codeList.CodeID; var entityResult = _repository.Insert(entity); _repository.SaveChanges(); return(new ResponseEntityVM() { StatusCode = System.Net.HttpStatusCode.Created, Result = entityResult }); } catch (Exception ex) { return(new ResponseEntityVM() { StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = $"There was an error assigning the policy: {ex.Message}" }); } }