public static StudentExam ProjectTo(this StudentExamRequest request, IMapper mapper) { StudentExam entity = mapper.Map <StudentExam>(request); entity.DateCreated = DateTime.Now; return(entity); }
public static void ProjectTo(this StudentExamRequest request, StudentExam entity) { entity.IsAbsent = request.IsAbsent; entity.IsClosed = request.IsClosed; entity.Note = request.Note; entity.BehaviorId = request.BehaviorId; entity.ExamId = request.ExamId; }
public override async Task AddAsync(object request) { if (!(request is StudentExamRequest)) { throw new Exception("Convert type not allowed"); } StudentExamRequest rq = (StudentExamRequest)request; var std = rq.ProjectTo(_mapper); await _repository.AddOrUpdateAsync(std); }
public override async Task UpdateAsync(object request) { if (!(request is StudentExamRequest)) { throw new Exception("Convert type not allowed"); } StudentExamRequest req = (StudentExamRequest)request; StudentExam entity = await _repository.GetByIdAsync(req.Id); if (entity == null) { throw new Exception("Student exam not found"); } req.ProjectTo(entity); await _repository.AddOrUpdateAsync(entity); }
public async Task <IHttpActionResult> UpdateStudentExam([FromBody] StudentExamRequest request) { try { if (ModelState.IsValid) { await _service.UpdateAsync(request); await _service.CommitAsync(); return(Ok()); } return(BadRequest(ModelState)); } catch (Exception ex) { await _service.RollbackAsync(); return(BadRequest(GetError(ex))); } }