public void AddWare(WareDto ware)
 {
     using (var context = new CassaContext(conStrName))
     {
         context.Wares.Add(new Ware
         {
             Price    = ware.Price,
             WareName = ware.WareName,
         });
         context.SaveChanges();
     }
 }
        public int CloseCheck(CheckDto check)
        {
            using (var context = new CassaContext(conStrName))
            {
                using (var tran = new TransactionScope())
                {
                    //добавляем новый чек
                    var checkDao = new Check
                    {
                        CashboxId = check.CashboxId,
                        CheckId   = check.CheckId,
                        DateTM    = check.DateTM ?? DateTime.Now,
                        Summ      = check.Summ,
                    };
                    checkDao.Details = check.Details.Select(x => new CheckDetail
                    {
                        Check         = checkDao,
                        WareId        = x.WareId,
                        CheckDetailId = x.CheckDetailId,
                        Price         = x.Price,
                        Qty           = x.Qty
                    }).ToList();
                    context.Checks.Add(checkDao);
                    context.SaveChanges();
                    //проводим движение товара и обновляем остатки
                    foreach (var det in check.Details)
                    {
                        context.Moves.Add(new Move
                        {
                            Qty       = det.Qty,
                            WareId    = det.WareId,
                            Kind      = CassaConst.MoveKind.mkOun,
                            MoveDate  = DateTime.Now,
                            MoveDocId = check.CheckId,
                        });

                        var rem = context.WareRems.FirstOrDefault(x => x.WareId == det.WareId);
                        if (rem.Qty < det.Qty)
                        {
                            throw new ApplicationException(
                                      $"Не хватате товара {rem.Ware.WareName}: в наличие {rem.Qty} требуется {det.Qty}!");
                        }

                        rem.Qty -= det.Qty;
                    }
                    context.SaveChanges();
                    //throw new ApplicationException("test");
                    tran.Complete();
                    return(checkDao.CheckId);
                }
            }
        }
        public List <WareDto> GetWareList(QueryParam param)
        {
            var wares = new List <WareDto>();

            using (var context = new CassaContext(conStrName))
            {
                IQueryable <Ware> query = context.Wares;
                if (!string.IsNullOrEmpty(param.Name))
                {
                    query = query.Where(x => x.WareName.StartsWith(param.Name));
                }
                if (param.Limit > 0)
                {
                    query = query.Take(param.Limit);
                }
                wares = query.Select(x => x).ToList().Select(WareDto.FromDao).ToList();
            }
            return(wares);
        }