public async Task <ResponseModel> CreateScientificReportTypeAsync(ScientificReportTypeManageModel scientificReportTypeManageModel) { var scientificReportType = await _scientificReportTypeRepository.FetchFirstAsync(x => x.Name == scientificReportTypeManageModel.Name); if (scientificReportType != null) { return(new ResponseModel { StatusCode = System.Net.HttpStatusCode.BadRequest, Message = "This scientificReportType is exist" }); } else { scientificReportType = new ScientificReportType(); scientificReportTypeManageModel.GetScientificReportTypeFromModel(scientificReportType); await _scientificReportTypeRepository.InsertAsync(scientificReportType); return(new ResponseModel { StatusCode = System.Net.HttpStatusCode.OK, Data = new ScientificReportTypeViewModel(scientificReportType), }); } }
public async Task <ResponseModel> UpdateScientificReportTypeAsync(Guid id, ScientificReportTypeManageModel scientificReportTypeManageModel) { var scientificReportType = await _scientificReportTypeRepository.GetByIdAsync(id); if (scientificReportType == null) { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.NotFound, Message = "This scientific report type is not exist" }); } else { var existedScientificReportTypeName = await _scientificReportTypeRepository.FetchFirstAsync(x => x.Name == scientificReportTypeManageModel.Name && x.Id != id); if (existedScientificReportTypeName != null) { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.BadRequest, Message = "Scientific Report Type " + scientificReportType.Name + " is exist on system. Please try again!", }); } else { scientificReportTypeManageModel.GetScientificReportTypeFromModel(scientificReportType); return(await _scientificReportTypeRepository.UpdateAsync(scientificReportType)); } } }
public async Task <IActionResult> Update(Guid id, [FromBody] ScientificReportTypeManageModel scientificReportTypeManageModel) { var response = await _scientificReportTypeService.UpdateScientificReportTypeAsync(id, scientificReportTypeManageModel); return(new CustomActionResult(response)); }