예제 #1
0
        public static Classroom ProjectTo(this AddClassroomRequest request, IMapper mapper)
        {
            Classroom cr = mapper.Map <Classroom>(request);

            cr.DateCreated = DateTime.Now;
            return(cr);
        }
예제 #2
0
        public override async Task AddAsync(object request)
        {
            if (!(request is AddClassroomRequest))
            {
                throw new Exception("Convert type not allowed");
            }

            AddClassroomRequest rq = (AddClassroomRequest)request;
            var cr = rq.ProjectTo(_mapper);

            // update student
            await _repository.AddOrUpdateAsync(cr);
        }
예제 #3
0
        public async Task <IHttpActionResult> AddClassroom([FromBody] AddClassroomRequest request)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _service.AddAsync(request);

                    await _service.CommitAsync();

                    return(Ok());
                }
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                await _service.RollbackAsync();

                return(BadRequest(GetError(ex)));
            }
        }