public async Task <IActionResult> Get(int id)
        {
            var item = await _mallDayRepository.GetSingleAsync(id);

            if (item == null)
            {
                return(NotFound());
            }
            var result = Mapper.Map <MallDayViewModel>(item);

            return(Ok(result));
        }
Esempio n. 2
0
        protected async Task <bool> HasMallDayBeenInitialized(DateTime?date = null)
        {
            var dateStr = !date.HasValue ? Now.AddDays(1).Date.ToString("yyyy-MM-dd") : date.Value.ToString("yyyy-MM-dd");
            var item    = await MallDayRepository.GetSingleAsync(x => x.Date == dateStr);

            return(item != null && item.Initialized);
        }
        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.MallProductSnapshots);

            var products = await _productRepository.All.Where(x => !x.Deleted).ToListAsync();

            var productForMalls = await _productForMallRepository.All.Where(x => !x.Deleted).ToListAsync();

            if (item != null)
            {
                if (item.Initialized)
                {
                    throw new Exception("该商超日已经初始化, 操作失败");
                }
                item.Initialized = true;
                item.SetModification(userName, "初始化");
                InitializeMallProducts(userName, item, productForMalls, products);
                _collectiveDayRepository.Update(item);
            }
            else
            {
                item = new MallDay
                {
                    Date        = dateStr,
                    Initialized = true
                };
                item.SetCreation(userName, "初始化");
                InitializeMallProducts(userName, item, productForMalls, products);
                _collectiveDayRepository.Add(item);
            }
        }