public static SchoolYear ProjectTo(this AddSchoolYearRequest request, IMapper mapper) { SchoolYear item = mapper.Map <SchoolYear>(request); item.DateCreated = DateTime.Now; return(item); }
public async override Task AddAsync(object request) { if (!(request is AddSchoolYearRequest)) { throw new Exception("Convert type not allowed"); } AddSchoolYearRequest rq = (AddSchoolYearRequest)request; var item = rq.ProjectTo(_mapper); // update student await _repository.AddOrUpdateAsync(item); }
public async Task <IHttpActionResult> AddSchoolYear([FromBody] AddSchoolYearRequest 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))); } }