//
        // 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);
            }
        }
Exemple #2
0
        public ActionResult ChangeQuantity(int id)
        {
            bool status = false;
            string message = "";
            int quantity = 0;

            try
            {
                var dbBalance = new EfBalanceItemRepository();
                var dbProducts = new EfProductRepository();

                var pd = dbProducts.GetDetailsById(id);
                if (pd == null)
                {
                    message = "Could not found ProductDetail";
                    ErrorFormat("Could not get ProductDetail by ID: {0}", id);
                }
                else
                {

                    var product = dbProducts.GetById(pd.ProductId);
                    if (product == null)
                    {
                        message = "Could not found Product to change quantity";
                        ErrorFormat("Could not get Product by ID: {0}", pd.ProductId);
                    }

                    var balanceItem = dbBalance.BalanceItems
                        .Where(x => x.InternalCode == product.InternalCode)
                        .Where(x => x.SizeName == pd.ParameterValue)
                        .Where(x => x.PosId == product.PosId)
                        .Where(x => x.StatusId == (byte)Status.Pending)
                        .FirstOrDefault();

                    int dQnt = int.Parse(Request["dQnt"]);
                    if (balanceItem == null)
                    {
                        balanceItem = new OnBalance.Domain.Entities.BalanceItem();
                        balanceItem.InternalCode = product.InternalCode;
                        balanceItem.SizeName = pd.ParameterValue;
                        balanceItem.PosId = product.PosId;
                        balanceItem.ProductName = product.Name;
                        balanceItem.StatusId = (byte)Status.Pending;
                        balanceItem.Quantity = dQnt;
                    }
                    else
                    {
                        balanceItem.Quantity += dQnt;
                    }

                    balanceItem.Price = pd.PriceMinor / 100;
                    balanceItem.PriceOfRelease = pd.PriceReleaseMinor / 100;
                    // Locally
                    balanceItem.ChangedFrom = 'L';

                    dbBalance.Save(balanceItem);
                    dbBalance.SubmitChanges();

                    quantity = balanceItem.Quantity;
                    status = true;
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            return Json(new {
                Staus = status,
                Message = message,
                Quantity = quantity
            }, JsonRequestBehavior.AllowGet);
        }