示例#1
0
        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),
                });
            }
        }
示例#2
0
        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));
                }
            }
        }
示例#3
0
        public async Task <IActionResult> Update(Guid id, [FromBody] ScientificReportTypeManageModel scientificReportTypeManageModel)
        {
            var response = await _scientificReportTypeService.UpdateScientificReportTypeAsync(id, scientificReportTypeManageModel);

            return(new CustomActionResult(response));
        }