public async Task <IActionResult> PutEndingCoursePointDetail(int id, EndingCoursePointDetailViewModel endingCoursePointDetail, Guid userId) { if (endingCoursePointDetail.Id != id) { throw new Exception(string.Format("Id và Id của giáo viên không giống nhau!")); } try { await Task.Run(() => { _endingCoursePointDetailService.Update(endingCoursePointDetail, userId); _endingCoursePointDetailService.SaveChanges(); return(Ok("Cập nhập thành công!")); }); } catch (DbUpdateConcurrencyException) { if (!EndingCoursePointDetailExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public bool Update(EndingCoursePointDetailViewModel endingCoursePointDetailVm, Guid userId) { try { var endingCoursePointDetail = Mapper.Map <EndingCoursePointDetailViewModel, EndingCoursePointDetail>(endingCoursePointDetailVm); endingCoursePointDetail.DateModified = DateTime.Now; endingCoursePointDetail.TotalPoint = endingCoursePointDetail.ListeningPoint + endingCoursePointDetail.SayingPoint + endingCoursePointDetail.ReadingPoint + endingCoursePointDetail.WritingPoint; endingCoursePointDetail.AveragePoint = (endingCoursePointDetail.ListeningPoint + endingCoursePointDetail.SayingPoint + endingCoursePointDetail.ReadingPoint + endingCoursePointDetail.WritingPoint) / 4; _endingCoursePointDetailRepository.Update(endingCoursePointDetail); _context.SaveChanges(); UpdateSortIndexRange(endingCoursePointDetail.EndingCoursePointId); _context.SaveChanges(); LogSystem logSystem = new LogSystem(); logSystem.PeriodicPointId = endingCoursePointDetail.EndingCoursePointId; logSystem.LecturerId = _endingCoursePoinRepository.FindById(endingCoursePointDetail.EndingCoursePointId).LecturerId; logSystem.UserId = userId; logSystem.Content = "Cập nhật điểm cuối khóa - Học viên: " + _learnerRepository.FindById(endingCoursePointDetail.LearnerId).FirstName + " " + _learnerRepository.FindById(endingCoursePointDetail.LearnerId).LastName + "- Lớp: " + _languageclassRepository.FindById(_endingCoursePoinRepository.FindById(endingCoursePointDetail.EndingCoursePointId).LanguageClassId).Name; logSystem.DateCreated = DateTime.Now; logSystem.DateModified = DateTime.Now; logSystem.IsManagerPointLog = true; _context.LogSystems.Add(logSystem); return(true); } catch { return(false); } }
public bool Add(EndingCoursePointDetailViewModel endingCoursePointDetailVm) { try { var endingCoursePointDetail = Mapper.Map <EndingCoursePointDetailViewModel, EndingCoursePointDetail>(endingCoursePointDetailVm); _endingCoursePointDetailRepository.Add(endingCoursePointDetail); return(true); } catch { return(false); } }
public async Task <ActionResult <EndingCoursePointDetailViewModel> > PostEndingCoursePointDetail(EndingCoursePointDetailViewModel endingCoursePointDetail) { if (endingCoursePointDetail != null) { try { await Task.Run(() => { _endingCoursePointDetailService.Add(endingCoursePointDetail); _endingCoursePointDetailService.SaveChanges(); return(Ok("Thêm giáo viên thành công!")); }); } catch { throw new Exception(string.Format("Lỗi khi thêm dữ liệu")); } } return(CreatedAtAction("GetEndingCoursePointDetails()", new { id = endingCoursePointDetail.Id }, endingCoursePointDetail)); }