public async Task <ResponseModel> UpdateOtherScientificWorkAsync(Guid id, OtherScientificWorkManageModel otherScientificWorkManageModel) { var otherScientificWork = await GetAll().FirstOrDefaultAsync(x => x.Id == id); if (otherScientificWork == null) { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.NotFound, Message = "This OtherScientificWork is not exist. Please try again!" }); } else { await _lecturerInOtherScientificWorkRepository.DeleteAsync(otherScientificWork.LecturerInOtherScientificWorks); var lecturerInOtherScientificWorks = new List <LecturerInOtherScientificWork>(); foreach (var lecturerId in otherScientificWorkManageModel.LecturerIds) { lecturerInOtherScientificWorks.Add(new LecturerInOtherScientificWork() { OtherScientificWorkId = otherScientificWork.Id, LecturerId = lecturerId }); } _lecturerInOtherScientificWorkRepository.GetDbContext().LecturerInOtherScientificWorks.AddRange(lecturerInOtherScientificWorks); await _lecturerInOtherScientificWorkRepository.GetDbContext().SaveChangesAsync(); otherScientificWorkManageModel.GetOtherScientificWorkFromModel(otherScientificWork); await _otherScientificWorkResponstory.UpdateAsync(otherScientificWork); otherScientificWork = await GetAll().FirstOrDefaultAsync(x => x.Id == id); return(new ResponseModel { StatusCode = System.Net.HttpStatusCode.OK, Data = new OtherScientificWorkViewModel(otherScientificWork) }); } }
public async Task <ResponseModel> CreateOtherScientificWorkAsync(OtherScientificWorkManageModel otherScientificWorkManageModel) { var otherScientificWork = await _otherScientificWorkResponstory.FetchFirstAsync(x => x.Name == otherScientificWorkManageModel.Name && x.ClassificationOfScientificWorkId == otherScientificWorkManageModel.ClassificationOfScientificWorkId); if (otherScientificWork != null) { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.BadRequest, Message = "This OtherScientificWork is exist. Can you try again with the update!" }); } else { otherScientificWork = _mapper.Map <OtherScientificWork>(otherScientificWorkManageModel); var classificationOfScientificWork = await _classificationOfScientificWorkRepository.GetByIdAsync(otherScientificWorkManageModel.ClassificationOfScientificWorkId); otherScientificWork.ClassificationOfScientificWork = classificationOfScientificWork; await _otherScientificWorkResponstory.InsertAsync(otherScientificWork); var lecturerInOtherScientificWorks = new List <LecturerInOtherScientificWork>(); foreach (var lecturerId in otherScientificWorkManageModel.LecturerIds) { lecturerInOtherScientificWorks.Add(new LecturerInOtherScientificWork() { OtherScientificWorkId = otherScientificWork.Id, LecturerId = lecturerId }); } _lecturerInOtherScientificWorkRepository.GetDbContext().LecturerInOtherScientificWorks.AddRange(lecturerInOtherScientificWorks); await _lecturerInOtherScientificWorkRepository.GetDbContext().SaveChangesAsync(); return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.OK, Data = new OtherScientificWorkViewModel(otherScientificWork) }); } }
public async Task <IActionResult> Update(Guid id, [FromBody] OtherScientificWorkManageModel otherScientificWorkManageModel) { var response = await _otherScientificWorkService.UpdateOtherScientificWorkAsync(id, otherScientificWorkManageModel); return(new CustomActionResult(response)); }
public async Task <IActionResult> Create([FromBody] OtherScientificWorkManageModel otherScientificWorkManagerModel) { var response = await _otherScientificWorkService.CreateOtherScientificWorkAsync(otherScientificWorkManagerModel); return(new CustomActionResult(response)); }