public static Classroom ProjectTo(this AddClassroomRequest request, IMapper mapper) { Classroom cr = mapper.Map <Classroom>(request); cr.DateCreated = DateTime.Now; return(cr); }
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); }
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))); } }