public void UpdateBlock(UpdateBlockModel model, int currUserId) { var block = _unitOfWork.Repository <BlockExersiceEntity>() .Include(x => x.Plan.Owner) .FirstOrDefault(x => x.Plan.Owner.Id == currUserId && x.Id == model.Id); if (block != null) { block.Name = model.Name; } _unitOfWork.SaveChanges(); }
public IHttpActionResult UpdateBlock(UpdateBlockModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _blockOperations.UpdateBlock(model, _currentUserProvider.CurrentUserId); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); throw; } }
public async Task <IActionResult> EditBlock([FromBody] UpdateBlockModel updateBlockModel) { var _user = await _userService.GetUserByEmailAsync(updateBlockModel.User.Email); bool isValidGUID = Guid.TryParse(_user.Student.Id.ToString(), out Guid guid); if (!isValidGUID) { return(ErrorResponse($"Student id: {_user.Student.Id.ToString()} is not valid GUID.")); } var student = await _studentService.FindByIdAsync(guid); if (student == null) { return(ErrorResponse($"Student with id: {updateBlockModel.User.Student.Id} does not exist.")); } if (student.Timetable == null) { return(ErrorResponse($"Timetable for student with id: {student.Id} does not exist.")); } Course newCourse = await _courseService.FindByCodeAsync(updateBlockModel.TimetableBlock.CourseCode); if (newCourse == null) { return(ErrorResponse($"New course: {updateBlockModel.TimetableBlock.CourseName} does not exist.")); } Block newBlock = TimetableBlock.ConvertToBlock(updateBlockModel.TimetableBlock, newCourse.Id); if (student.Timetable.UpdateBlock(newBlock)) { student.Timetable.UpdateColorOfBlocksWithSameCourseId(newBlock); await _studentService.UpdateStudentAsync(student); } else { return(ErrorResponse($"Block {newBlock.ToString()} is not updated")); } return(Ok(newBlock)); }