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