public ResponseMessageResult Analogues(int kagId, string number, string brand)
        {
            var ctx = new valmiEntities();

            NomenclatureElement[] result = null;

            var r = ctx.vsspGetWare(null, kagId, null, null, number, brand, true, null).FirstOrDefault();

            if (r != null)
            {
                var foundRows = new ObjectParameter("RowCnt", 1);
                var analogue  = ctx.vsspGetWareChange(r.WareId, kagId, null, null, true, null, foundRows, true, false);
                // vsspGetWareReplacements(null, r.WareId, kagId, null, false, out var rowCnt);
                result = analogue.Select(i => new NomenclatureElement
                {
                    Brand       = i.ProducerName,
                    WareName    = i.WareName,
                    WareId      = i.WareId,
                    UnitName    = i.UnitShName,
                    WareNum     = i.WareNum,
                    Price       = i.PriceOut ?? 0,
                    WareNameRom = i.WareName,
                    UnitCode    = 5
                }).ToArray();
            }

            /*
             *      var ctx = new CatalogRepository();
             *
             *      NomenclatureElement[] result = null;
             *
             *      var r = ctx.GetWare(null, brand, number, kagId, null);
             *      if (r != null)
             *      {
             *          var analogue = ctx.GetWareReplacements(null, r.Id, kagId, null, false, out var rowCnt);
             *          result = analogue.Select(i => new NomenclatureElement
             *          {
             *              Brand = i.ProducerName,
             *              WareName = i.Name,
             *              WareId = i.Id,
             *              UnitName = i.MeasureUnit,
             *              WareNum = i.WareNum,
             *              Price = i.ClientPrice ?? 0,
             *              WareNameRom = i.Name,
             *              UnitCode = 5
             *          }).ToArray();
             *
             *      }
             */
            return(XmlResponseMessage(result));
        }
        public ResponseMessageResult CreateOrder(int orderId, int kagId)
        {
            var user = GetUser(kagId);

            if (user == null)
            {
                return(ForbiddenResponseMessage);
            }

            var ctx = new valmiEntities();

            var result = ctx.vsspCreateOrder(kagId, null, user.Id, null).FirstOrDefault();


            return(XmlResponseMessage(result));
        }
        public ResponseMessageResult Orders(string startDate, string endDate, int kagId)
        {
            var user = GetUser(kagId);

            if (user == null)
            {
                return(ForbiddenResponseMessage);
            }

            var ctx = new valmiEntities();

            var result = ctx.vsspGetOrderList(kagId, null,
                                              DateTime.TryParseExact(startDate, "ddMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateBeg) ? (DateTime?)dateBeg : null,
                                              DateTime.TryParseExact(endDate, "ddMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateEnd) ? (DateTime?)dateEnd : null, null, null, null).ToArray();

            return(XmlResponseMessage(result));
        }
        public ResponseMessageResult Order(int orderId, int kagId)
        {
            var user = GetUser(kagId);

            if (user == null)
            {
                return(ForbiddenResponseMessage);
            }

            var ctx = new valmiEntities();

            var result = new Order
            {
                OrderData      = ctx.vsspGetOrderData(kagId, null, null).FirstOrDefault(),
                OrderPositions = ctx.vsspGetOrderPositions(orderId, kagId, null).ToArray()
            };

            return(XmlResponseMessage(result));
        }