public IActionResult SaveEntity(DirectionViewModel directionVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (directionVm.Id == 0) { _directionService.Add(directionVm); } else { _directionService.Update(directionVm); } _directionService.Save(); return(new OkObjectResult(directionVm)); }
public async Task <IHttpActionResult> PutDirection(int id, DirectionModel directionModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != directionModel.Id) { return(BadRequest()); } var direction = _directionService.GetDirectionById(id); ObjectFactory.Parse(directionModel, direction); _directionService.Update(direction); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DirectionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Put(List <DirectionDto> list) { return(Ok(_service.Update(list))); }