Пример #1
0
        //
        // POST: /parser/import

        public ActionResult Import()
        {
            try
            {
                var parsed = TempData["ExchangeItems"] as List <ParsedItem>;
                if (parsed == null)
                {
                    throw new ArgumentNullException("Information about sizes", "No parsed items. Bad data?!");
                }

                var db = new EfProductRepository();
                foreach (var item in parsed)
                {
                    var product = new OnBalance.Domain.Entities.Product();
                    //product.CategoryId =
                    product.InternalCode = item.InternalCode;
                    product.Name         = item.ProductName;
                    product.PosId        = 500000;
                    product.Price        = item.PriceOfRelease;
                    product.StatusId     = (byte)Status.Pending;
                    product.UserId       = User.Identity.Name;
                    product.Uid          = Common.EncodeHex(Common.CalculateMd5(string.Format("{0}-{1}-{2}", User.Identity.Name, product.PosId, product.InternalCode)));
                    product.CreatedAt    = DateTime.UtcNow;
                    db.Save(product);

                    foreach (var size in item.Sizes)
                    {
                        var pd = new OnBalance.Domain.Entities.ProductDetail();
                        pd.ProductId         = product.Id;
                        pd.ParameterName     = "size";
                        pd.ParameterValue    = size.Size;
                        pd.Quantity          = size.Quantity;
                        pd.StatusId          = (byte)Status.Pending;
                        pd.PriceMinor        = (int)(item.Price * 100);
                        pd.PriceReleaseMinor = (int)(item.PriceOfRelease * 100);
                        pd.CreatedAt         = DateTime.UtcNow;
                        pd.UpdatedAt         = DateTime.UtcNow;
                        db.Save(pd);
                    }

                    //var bi = new OnBalance.Domain.Entities.BalanceItem();
                    //bi.InternalCode = item.InternalCode;
                    //bi.PosId = 500001;
                    //bi.Price = item.Price;
                    //bi.PriceOfRelease = item.PriceOfRelease;
                    //bi.ProductName = item.ProductName;
                    //bi.Quantity = item.Quantity;
                    //bi.StatusId = (byte)OnBalance.Status.Pending;
                    //db.Save(bi);
                }
                db.SubmitChanges();

                return(View("Import", "_LayoutLogin"));
            }
            catch (Exception ex)
            {
                Error("Error importing parsed products", ex);
                return(Content(ex.Message));
            }
        }
Пример #2
0
        public ActionResult DoNewSize(int id)
        {
            string sizeName = "";
            var    pd       = new OnBalance.Domain.Entities.ProductDetail();
            bool   status   = false;
            var    sb       = new StringBuilder();

            try
            {
                Info("Adding new size...");
                sizeName = Request["sname"].Trim().ToUpper();
                var details = _productRepository.GetDetailsByProduct(id);
                if (details.FirstOrDefault(x => x.ParameterValue == sizeName) != null)
                {
                    throw new ArgumentException("Size already exists: " + sizeName);
                }

                pd.Quantity       = 0;
                pd.ParameterValue = sizeName;
                pd.ParameterName  = "size";
                pd.ProductId      = id;
                pd.CreatedAt      = DateTime.UtcNow;
                pd.UpdatedAt      = DateTime.UtcNow;
                pd.StatusId       = (byte)Status.Pending;
                pd.DataJson       = "";

                _productRepository.Save(pd);
                _productRepository.SubmitChanges();

                sb.AppendFormat("<div id=\"Qnt_{0}\" class=\"product-qnt\">{1}</div>", pd.Id, pd.Quantity);
                sb.AppendFormat("<div id=\"Decrease_{0}\" class=\"product-qnt-minus\"><img alt=\"-\" height=\"3\" src=\"/images/decrease.gif\" title=\"-\" width=\"6\"></div>", pd.Id);
                sb.AppendFormat("<div id=\"Increase_{0}\" class=\"product-qnt-plus\"><img alt=\"+\" height=\"3\" src=\"/images/increase.gif\" title=\"+\" width=\"6\"></div>", pd.Id);
                status = true;
            }
            catch (Exception ex)
            {
                Error("Error adding quantity for size: " + sizeName, ex);
                //resp.Message = ex.Message;
            }

            return(Json(new
            {
                Status = status,
                HtmlData = sb.ToString(),
                NewSizeId = pd.Id
            }));
        }
Пример #3
0
        //
        // POST: /parser/import
        public ActionResult Import()
        {
            try
            {
                var parsed = TempData["ExchangeItems"] as List<ParsedItem>;
                if (parsed == null)
                {
                    throw new ArgumentNullException("Information about sizes", "No parsed items. Bad data?!");
                }

                var db = new EfProductRepository();
                foreach (var item in parsed)
                {
                    var product = new OnBalance.Domain.Entities.Product();
                    //product.CategoryId =
                    product.InternalCode = item.InternalCode;
                    product.Name = item.ProductName;
                    product.PosId = 500000;
                    product.Price = item.PriceOfRelease;
                    product.StatusId = (byte)Status.Pending;
                    product.UserId = User.Identity.Name;
                    product.Uid = Common.EncodeHex(Common.CalculateMd5(string.Format("{0}-{1}-{2}", User.Identity.Name, product.PosId, product.InternalCode)));
                    product.CreatedAt = DateTime.UtcNow;
                    db.Save(product);

                    foreach (var size in item.Sizes)
                    {
                        var pd = new OnBalance.Domain.Entities.ProductDetail();
                        pd.ProductId = product.Id;
                        pd.ParameterName = "size";
                        pd.ParameterValue = size.Size;
                        pd.Quantity = size.Quantity;
                        pd.StatusId = (byte)Status.Pending;
                        pd.PriceMinor = (int)(item.Price * 100);
                        pd.PriceReleaseMinor = (int)(item.PriceOfRelease * 100);
                        pd.CreatedAt = DateTime.UtcNow;
                        pd.UpdatedAt = DateTime.UtcNow;
                        db.Save(pd);
                    }

                    //var bi = new OnBalance.Domain.Entities.BalanceItem();
                    //bi.InternalCode = item.InternalCode;
                    //bi.PosId = 500001;
                    //bi.Price = item.Price;
                    //bi.PriceOfRelease = item.PriceOfRelease;
                    //bi.ProductName = item.ProductName;
                    //bi.Quantity = item.Quantity;
                    //bi.StatusId = (byte)OnBalance.Status.Pending;
                    //db.Save(bi);
                }
                db.SubmitChanges();

                return View("Import", "_LayoutLogin");
            }
            catch (Exception ex)
            {
                Error("Error importing parsed products", ex);
                return Content(ex.Message);
            }
        }
Пример #4
0
        public ActionResult DoNewSize(int id)
        {
            string sizeName = "";
            var pd = new OnBalance.Domain.Entities.ProductDetail();
            bool status = false;
            var sb = new StringBuilder();
            try
            {
                Info("Adding new size...");
                sizeName = Request["sname"].Trim().ToUpper();
                var details = _productRepository.GetDetailsByProduct(id);
                if (details.FirstOrDefault(x => x.ParameterValue == sizeName) != null)
                {
                    throw new ArgumentException("Size already exists: " + sizeName);
                }

                pd.Quantity = 0;
                pd.ParameterValue = sizeName;
                pd.ParameterName = "size";
                pd.ProductId = id;
                pd.CreatedAt = DateTime.UtcNow;
                pd.UpdatedAt = DateTime.UtcNow;
                pd.StatusId = (byte)Status.Pending;
                pd.DataJson = "";

                _productRepository.Save(pd);
                _productRepository.SubmitChanges();

                sb.AppendFormat("<div id=\"Qnt_{0}\" class=\"product-qnt\">{1}</div>", pd.Id, pd.Quantity);
                sb.AppendFormat("<div id=\"Decrease_{0}\" class=\"product-qnt-minus\"><img alt=\"-\" height=\"3\" src=\"/images/decrease.gif\" title=\"-\" width=\"6\"></div>", pd.Id);
                sb.AppendFormat("<div id=\"Increase_{0}\" class=\"product-qnt-plus\"><img alt=\"+\" height=\"3\" src=\"/images/increase.gif\" title=\"+\" width=\"6\"></div>", pd.Id);
                status = true;
            }
            catch (Exception ex)
            {
                Error("Error adding quantity for size: " + sizeName, ex);
                //resp.Message = ex.Message;
            }

            return Json(new
            {
                Status = status,
                HtmlData = sb.ToString(),
                NewSizeId = pd.Id
            });
        }