public ActionResponse Add(SectorTypesModel model) { using (var unitWork = new UnitOfWork(context)) { ActionResponse response = new ActionResponse(); try { var newSectorTypes = unitWork.SectorTypesRepository.Insert(new EFSectorTypes() { TypeName = model.TypeName, IsPrimary = model.IsPrimary, SourceUrl = model.SourceUrl, IATICode = model.IATICode, IsSourceType = false }); response.ReturnedId = newSectorTypes.Id; unitWork.Save(); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); } }
public IActionResult Put(int id, [FromBody] SectorTypesModel sectorType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = sectorTypeService.Update(id, sectorType); if (!response.Success) { return(BadRequest(response.Message)); } return(Ok(response.Message)); }
public IActionResult Post([FromBody] SectorTypesModel sectorType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = sectorTypeService.Add(sectorType); if (!response.Success) { return(BadRequest(response.Message)); } return(Ok(response.ReturnedId)); }
public ActionResponse Update(int id, SectorTypesModel model) { using (var unitWork = new UnitOfWork(context)) { ActionResponse response = new ActionResponse(); var sectorTypeObj = unitWork.SectorTypesRepository.GetByID(id); if (sectorTypeObj == null) { IMessageHelper mHelper = new MessageHelper(); response.Success = false; response.Message = mHelper.GetNotFound("SectorTypes"); return(response); } sectorTypeObj.TypeName = model.TypeName; unitWork.Save(); response.Message = "1"; return(response); } }