public ActionResponse Add(FundingTypeModel model) { using (var unitWork = new UnitOfWork(context)) { ActionResponse response = new ActionResponse(); try { var isFundingTypeCreated = unitWork.FundingTypeRepository.GetOne(l => l.FundingType.ToLower() == model.FundingType.ToLower()); if (isFundingTypeCreated != null) { response.ReturnedId = isFundingTypeCreated.Id; } else { var newFundingType = unitWork.FundingTypeRepository.Insert(new EFFundingTypes() { FundingType = model.FundingType, }); unitWork.Save(); response.ReturnedId = newFundingType.Id; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); } }
public IActionResult Put(int id, [FromBody] FundingTypeModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = fundingTypeService.Update(id, model); if (!response.Success) { return(BadRequest(response.Message)); } return(Ok(true)); }
public IActionResult Post([FromBody] FundingTypeModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = fundingTypeService.Add(model); if (!response.Success) { return(BadRequest(response.Message)); } return(Ok(response.ReturnedId)); }
public ActionResponse Update(int id, FundingTypeModel model) { using (var unitWork = new UnitOfWork(context)) { ActionResponse response = new ActionResponse(); var FundingTypeObj = unitWork.FundingTypeRepository.GetByID(id); if (FundingTypeObj == null) { IMessageHelper mHelper = new MessageHelper(); response.Success = false; response.Message = mHelper.GetNotFound("FundingType"); return(response); } FundingTypeObj.FundingType = model.FundingType; unitWork.FundingTypeRepository.Update(FundingTypeObj); unitWork.Save(); response.Message = true.ToString(); return(response); } }