public IHttpActionResult PostCrashType(CrashTypeViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var crashType = Mapper.Map <CrashTypeViewModel, CrashType>(viewModel); crashType.CreatedAt = DateTime.Now; UnitOfWork.Repository <CrashType>().Insert(crashType); UnitOfWork.Save(); return(Ok()); }
public IHttpActionResult PutCrashType(CrashTypeViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var crashType = UnitOfWork.Repository <CrashType>() .Get(x => x.CrashTypeId == viewModel.CrashTypeId) .SingleOrDefault(); if (crashType == null) { return(BadRequest()); } Mapper.Map <CrashTypeViewModel, CrashType>(viewModel, crashType); crashType.UpdatedAt = DateTime.Now; UnitOfWork.Repository <CrashType>().Update(crashType); try { UnitOfWork.Save(); } catch (DbUpdateConcurrencyException) { if (!CrashTypeExists(viewModel.CrashTypeId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }