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