Example #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));
            }
        }
Example #2
0
        public void StoresAndLoadsProduct()
        {
            Product            product           = new Product("cup", new Money(1, 25));
            IProductRepository productRepository = new EfProductRepository(CreateCommerceContext());

            var id = productRepository.Save(product);

            Product loaded = productRepository.FindOne(id);

            loaded.ShouldBeEquivalentTo(product);
        }