コード例 #1
0
        public static StudentExam ProjectTo(this StudentExamRequest request, IMapper mapper)
        {
            StudentExam entity = mapper.Map <StudentExam>(request);

            entity.DateCreated = DateTime.Now;
            return(entity);
        }
コード例 #2
0
 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;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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)));
            }
        }