public async Task Initialzie(DateTime date, string userName) { var dateStr = date.ToString("yyyy-MM-dd"); var item = await _retailDayRepository.GetSingleAsync(x => x.Date == dateStr, x => x.RetailProductSnapshots); var products = await _productRepository.All.Where(x => !x.Deleted).ToListAsync(); var productForRetails = await _productForRetailRepository.All.Where(x => !x.Deleted).ToListAsync(); if (item != null) { if (item.Initialized) { throw new Exception("该零售日已经初始化, 操作失败"); } item.Initialized = true; item.SetModification(userName, "初始化"); InitializeRetailProducts(userName, item, productForRetails, products); _retailDayRepository.Update(item); } else { item = new RetailDay { Date = dateStr, Initialized = true }; item.SetCreation(userName, "初始化"); InitializeRetailProducts(userName, item, productForRetails, products); _retailDayRepository.Add(item); } }
public async Task <IActionResult> Put(int id, [FromBody] RetailDayViewModel retailDayVm) { if (retailDayVm == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dbItem = await _retailDayRepository.GetSingleAsync(id); if (dbItem == null) { return(NotFound()); } Mapper.Map(retailDayVm, dbItem); dbItem.SetModification(UserName); _retailDayRepository.Update(dbItem); if (!await UnitOfWork.SaveAsync()) { return(StatusCode(500, "保存时出错")); } return(NoContent()); }