public async Task <IActionResult> Post([FromBody] SubscriptionProductSnapshotViewModel subscriptionProductSnapshotVm) { if (subscriptionProductSnapshotVm == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newItem = Mapper.Map <SubscriptionProductSnapshot>(subscriptionProductSnapshotVm); newItem.SetCreation(UserName); _subscriptionProductSnapshotRepository.Add(newItem); if (!await UnitOfWork.SaveAsync()) { return(StatusCode(500, "保存时出错")); } var vm = Mapper.Map <SubscriptionProductSnapshotViewModel>(newItem); return(CreatedAtRoute("GetSubscriptionProductSnapshot", new { id = vm.Id }, vm)); }