public async Task <OutputResponse> Update(HealthFacilityResourceDTO resource) { var resourceToUpdate = await _context.HealthFacilityResources.FirstOrDefaultAsync(x => x.FacilityResourceId.Equals(resource.FacilityResourceId)); if (resourceToUpdate == null) { return(new OutputResponse { IsErrorOccured = true, Message = "Health facility resource specified does not exist, update cancelled" }); } //update details resourceToUpdate.CenterId = resource.CenterId; resourceToUpdate.ResourceAllocationId = resource.ResourceAllocationId; resourceToUpdate.Quantity = resource.Quantity; resourceToUpdate.RowAction = "U"; resourceToUpdate.ModifiedBy = resource.CreatedBy; resourceToUpdate.DateModified = DateTime.UtcNow.AddHours(2); await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.UpdateSuccess }); }
public async Task <IActionResult> Update([FromBody] HealthFacilityResourceDTO healthFacilityResource) { var outputHandler = await _service.Update(healthFacilityResource); if (outputHandler.IsErrorOccured) { return(BadRequest(outputHandler.Message)); } return(Ok(outputHandler.Message)); }
public async Task <OutputResponse> Add(HealthFacilityResourceDTO resource) { var mappedHealthFacilityResource = new AutoMapperHelper <HealthFacilityResourceDTO, HealthFacilityResources>().MapToObject(resource); mappedHealthFacilityResource.RowAction = "I"; mappedHealthFacilityResource.DateCreated = DateTime.UtcNow.AddHours(2); await _context.HealthFacilityResources.AddAsync(mappedHealthFacilityResource); await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.AddNewSuccess }); }