public IActionResult Put(int id, [FromBody] StandardServiceProvidedViewModel standardServiceProvidedViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Get the StandardService to Edit var _standardService = _unitOfWork.StandardServiceProvided .GetSingle(id); if (_standardService == null) { return(NotFound()); } else { _standardService.Code = standardServiceProvidedViewModel.Code; _standardService.Comment = standardServiceProvidedViewModel.Comment; _standardService.Description = standardServiceProvidedViewModel.Description; _standardService.LongName = standardServiceProvidedViewModel.LongName; _standardService.ShortName = standardServiceProvidedViewModel.ShortName; // Put logic to handle inputer, maker, checker } standardServiceProvidedViewModel = _mapper.Map <StandardServiceProvided, StandardServiceProvidedViewModel>(_standardService); return(new NoContentResult()); }
public IActionResult Post([FromBody] StandardServiceProvidedViewModel standardServiceProvidedViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Create the StandardService var newStandardService = _mapper.Map <StandardServiceProvidedViewModel, StandardServiceProvided>(standardServiceProvidedViewModel); _unitOfWork.StandardServiceProvided.Add(newStandardService); // Commit changes to the database to get StandardServiceId _unitOfWork.SaveChanges(); CreatedAtRouteResult result = CreatedAtRoute("Get", new { controller = "StandardServices", id = newStandardService.Id }, newStandardService); return(result); }