public async Task <IActionResult> Put(int id, [FromBody] MallPriceViewModel mallPriceVm) { if (mallPriceVm == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dbItem = await _mallPriceRepository.GetSingleAsync(id); if (dbItem == null) { return(NotFound()); } Mapper.Map(mallPriceVm, dbItem); dbItem.SetModification(UserName); _mallPriceRepository.Update(dbItem); if (!await UnitOfWork.SaveAsync()) { return(StatusCode(500, "保存时出错")); } return(NoContent()); }
public async Task <IActionResult> Post([FromBody] MallPriceViewModel mallPriceVm) { if (mallPriceVm == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newItem = Mapper.Map <MallPrice>(mallPriceVm); newItem.SetCreation(UserName); _mallPriceRepository.Add(newItem); if (!await UnitOfWork.SaveAsync()) { return(StatusCode(500, "保存时出错")); } var vm = Mapper.Map <MallPriceViewModel>(newItem); return(CreatedAtRoute("GetMallPrice", new { id = vm.Id }, vm)); }