public IActionResult AddPlanAddOns([FromBody] InsurancePlanAddOns item) { try { //InsuranceCompanyOptionalCover InsuranceCompanyOptionalCover = new InsuranceCompanyOptionalCover //{ // InsuranceCompanyId = InsuranceCompanyId, // OptionalCoverId = OptionalCoverId //}; _itemService.AddPlanAddOns(item); return(Ok(item)); } catch (AppException ex) { return(DefaultError(ex.Message)); } }
public InsurancePlanAddOns AddPlanAddOns(InsurancePlanAddOns item) { //var OptionalCover = _context.OptionalCover.Find(item.OptionalCoverId); if (!_context.Covers.Any(u => u.Id == item.CoverId)) { throw new AppException("Insurance Plan not found"); } if (!_context.InsuranceAddOns.Any(r => r.Id == item.InsuranceAddOnsId && r.DeletedAt == null)) { throw new AppException("AddOns not found"); } if (_context.InsurancePlanAddOns.Any(r => r.CoverId == item.CoverId && r.InsuranceAddOnsId == item.InsuranceAddOnsId)) { //_context.InsurancePlanAddOns.Update(item); throw new AppException("Plan AddOns is already exists"); } else { _context.InsurancePlanAddOns.Add(item); } _context.SaveChanges(); // validation //else if (string.IsNullOrWhiteSpace(item.Code)) //{ // exception = "Code is required"; // return false; // //throw new AppException("LoginProviderId is required"); //} return(item); }