Beispiel #1
1
        public OrderLine(Product product, int quantity, IList<Outcome> outcomes):this()
        {
            Product = product;
            Quantity = quantity;
            Price = product.Price;
            ProductName = product.Name;

            Outcomes = outcomes;
            outcomes.ForEach(x => x.OrderLine = this);

            Profit = Outcomes.Sum(outcome => outcome.Profit);
            SummWithDiscount = Outcomes.Sum(outcome => outcome.SummWithDiscount);

        }
Beispiel #2
0
 public void Add(Product product, int quantity)
 {
     var productInCart = Items.SingleOrDefault(x => x.Product.Id == product.Id);
     if (productInCart == null)
         Items.Add(new CartItem(){Product = product, Quantity = quantity});
     else
     {
         productInCart.Quantity += quantity;
     }
 }
Beispiel #3
0
        public ActionResult Create(ProductViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return View(viewModel);
            }
            Product product = new Product();
            product.Date = DateTime.UtcNow;
            product.CopyFrom(viewModel);
            daoTemplate.Save(product);

            handleImages(product);

            return RedirectToAction("Edit", new {Id = product.Id});
        }
Beispiel #4
0
        public void SetUp()
        {
            _product = new Product() { Id = 1 };

            _incomesForProduct = new List<Income>
                                     {
                                         new Income()
                                             {
                                                 BuyPrice = 10,
                                                 Date = new DateTime(2000, 6, 28),
                                                 Id = 1,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 20,
                                                 Date = new DateTime(2000, 5, 28),
                                                 Id = 2,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 30,
                                                 Date = new DateTime(2000, 4, 28),
                                                 Id = 3,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 40,
                                                 Date = new DateTime(2000, 3, 28),
                                                 Id = 4,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 50,
                                                 Date = new DateTime(2000, 2, 28),
                                                 Id = 5,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                     };

            _emptyIncome = new Income()
                               {
                                   BuyPrice = 50,
                                   Date = new DateTime(1980, 2, 28),
                                   Id = 6,
                                   Product = _product,
                                   QuantityCurrent = 0,
                                   QuantityInital = 0
                               };
            _incomesForProduct.Add(_emptyIncome);
            _product.Incomes = _incomesForProduct;

            _cartItems = new List<CartItem>
                             {
                                 new CartItem() {Product = _product, Quantity = 33}
                             };
            _user = new User() { };
            _shippingInfo = new OrderShippingInfo() { };

            _daoTemplate = new Mock<IDaoTemplate>();
            _daoTemplate.Setup(x => x.FindByID<Product>(1)).Returns(_product);
            _daoTemplate.Setup(x => x.FindByID<UniqueId>(0)).Returns(new UniqueId() { Uid = 123 });

            _orderService = new OrderService();
            _orderService.DaoTemplate = _daoTemplate.Object;
        }
Beispiel #5
0
        public void AddProducts()
        {
            string[] productNames = { "HTC Desire", "Nikon D3000 Kit", "Samsung LE-32C530", "Nokia E52", "Sony Ericsson XPERIA X10", "Canon EOS 500D Kit", "Sony PRS-600 Reader Touch Edition", "HTC Legend", "Lenovo IdeaPad Y550", "Samsung GT-I9000 Galaxy S", "Samsung R530", "Nokia 5228", "Nokian Hakkapeliitta 5", "Panasonic SR-TMH18", "Nokia 5530 XpressMusic", "Apple MacBook Pro 13 Mid 2010", "Nokia X6 16Gb" };
            string[] colors = { "Красный", "Зеленй", "Желтый" };
            string[] countries = { "Россия", "Китай", "Германия", "Австрия", "Канада" };
            string[] shortDescriptions = { "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent quis elit odio. Vestibulum ante ipsum primis in faucibus orci ", "Etiam convallis, urna ac faucibus sodales, lorem ligula malesuada metus, vitae pellentesque magna purus sit amet sapien.", "Praesent sapien magna, rhoncus nec dignissim vitae, ultrices pulvinar ligula. Pellentesque vitae sodales ipsum.", "Curabitur quis arcu in libero lobortis tristique ac sed turpis. Aenean sodales ornare leo id accumsan.", "Pellentesque sed ultricies lectus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In euismod tincidunt dolor vitae hendrerit.", "Etiam mollis libero nec eros vulputate faucibus. Morbi sagittis lacus tincidunt dui dapibus et volutpat nunc venenatis.", "Vivamus feugiat semper euismod. Duis cursus magna at dolor faucibus ut pharetra nunc rhoncus.", "In molestie mauris sit amet turpis bibendum pharetra nec eu lacus. Duis suscipit velit a diam accumsan nec scelerisque turpis fermentum.", "Donec tristique quam vel justo viverra in semper leo viverra. Etiam vel nisi in mi fringilla vehicula ullamcorper nec tellus." };
            string[] descriptions = {@"<ul>
            <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
            <li>Nam vitae augue augue, id volutpat felis.</li>

            <li>Pellentesque faucibus dolor ut nisi placerat imperdiet.</li>
            <li>Nulla aliquam elit eu enim bibendum pharetra venenatis ligula lacinia.</li>
            <li>Sed placerat massa id tellus laoreet sollicitudin.</li>
            <li>Pellentesque at augue nec mi vehicula viverra.</li>
            <li>Etiam posuere erat vel tellus congue in dictum metus accumsan.</li>
            <li>Donec a urna augue, ullamcorper sagittis odio.</li>
            </ul>
            ", @"<ul>
            <li>Etiam ut sem diam, at faucibus purus.</li>

            <li>Nulla eleifend urna sed massa viverra sit amet ornare magna varius.</li>
            <li>Fusce et leo velit, nec lobortis nulla.</li>
            <li>Curabitur id orci vel eros molestie imperdiet.</li>
            </ul>
            ", @"<ul>
            <li>Morbi adipiscing eros sit amet lectus tincidunt scelerisque.</li>
            <li>Cras rhoncus adipiscing turpis, sit amet tempor orci rhoncus eget.</li>
            <li>Morbi quis erat sit amet elit pretium rhoncus nec eu urna.</li>
            <li>Etiam sodales neque eget tortor eleifend consectetur.</li>

            </ul>
            ", @"<ul>
            <li>Maecenas lacinia venenatis tortor, vel suscipit augue gravida at.</li>
            <li>Phasellus et nulla ut lacus tempus cursus sed a mauris.</li>
            <li>Nunc lacinia tempor felis, at elementum lectus consectetur a.</li>
            </ul>
            ", @"<ul>
            <li>Nam sed justo tellus, ut pretium neque.</li>
            <li>Cras fringilla mauris sed libero interdum et consequat purus commodo.</li>

            <li>Duis molestie arcu et diam scelerisque sed laoreet dolor volutpat.</li>
            <li>Nam ac est vel nisl vehicula porttitor id eu nisl.</li>
            <li>Sed quis purus sed tellus tincidunt dapibus.</li>
            <li>Proin eget metus tellus, quis imperdiet risus.</li>
            <li>Suspendisse eget enim nunc, ut viverra nisi.</li>
            </ul>
            "};

            ISession session = GetConfiguration().BuildSessionFactory().OpenSession();
            IList<Category> categories = session.CreateCriteria(typeof (Category)).List<Category>();
            Random random = new Random();

            foreach (Category category in categories)
            {
                int n = random.Next(1, 5)*10;
                for(int i = 0; i < n; i++)
                {

                    Product product = new Product()
                                          {
                                              Category = category,
                                              Description = descriptions[random.Next(descriptions.Length)],
                                              Name = productNames[random.Next(productNames.Length)],
                                              Price = random.Next(1, 250)*100,
                                              ShortDescription =
                                                  shortDescriptions[random.Next(shortDescriptions.Length)],
                                              SKU = Guid.NewGuid().ToString(),
                                              Size = i > random.Next(5) ? random.Next(300).ToString() : "",
                                              Weight = i > random.Next(3) ? random.Next(300).ToString() : "",
                                              Country = i > random.Next(4) ? countries[random.Next(countries.Length)] : "",
                                              Color = i > random.Next(6) ? colors[random.Next(colors.Length)] : "",
                                              IsNew = i % 5 == 0
                                          };
                    session.Save(product);

                    product.Name = string.Format("[{0}] {1}", product.Id, category.Name);
                    session.Save(product);

                    for (int j = 0; j < random.Next(10); j++)
                    {
                        Income income = new Income()
                        {
                            BuyPrice = (decimal) ((double)product.Price * (0.5 * random.NextDouble())),
                            Product = product,
                            QuantityCurrent = random.Next(100)
                        };
                        income.QuantityInital = income.QuantityCurrent;
                        session.Save(income);
                    }

                }
            }

            session.Flush();
        }
Beispiel #6
0
 public virtual bool Equals(Product other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Price == Price;
 }
Beispiel #7
0
        private void handleImages(Product product)
        {
            foreach (string inputTagName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[inputTagName];
                if (file.ContentLength == 0) continue;
                Image image = new Image();
                image.PathRootBased = "";
                daoTemplate.Save(image);
                // TODO check for mime type
                // TODO add support for GIF, PNG
                if (file.ContentLength > 0)
                {
                    string filePath = Path.Combine(HttpContext.Server.MapPath("../Content/Uploads"), image.Big);
                    string thumbFilePath = Path.Combine(HttpContext.Server.MapPath("../Content/Uploads"), image.Small);
                    file.SaveAs(filePath);

                    ImageUtils.SaveImageToFile(ImageUtils.ResizeImage(filePath, 640), filePath);
                    ImageUtils.SaveImageToFile(ImageUtils.ResizeImageSquare(filePath), thumbFilePath);

                }
                product.Images.Add(image);
                daoTemplate.Save(product);
            }
        }
Beispiel #8
0
 public IList<Income> FindOldestIncomesForProduct(Product product, int quantity)
 {
     product = _daoTemplate.FindByID<Product>(product.Id);
     List<Income> result = new List<Income>();
     foreach (Income income in product.Incomes.OrderBy(x => x.Date))
     {
         if (income.QuantityCurrent == 0)
         {
             continue;
         }
         result.Add(income);
         quantity -= Math.Min(income.QuantityCurrent, quantity);
         if (quantity == 0)
         {
             break;
         }
     }
     if (quantity > 0)
     {
         // not enough products in stock
     }
     return result;
 }
Beispiel #9
0
        public static ProductViewModel From(Product product)
        {
            ProductViewModel viewModel = new ProductViewModel();
            viewModel.CategoryId = product.Category.Id;
            viewModel.Description = product.Description;
            viewModel.ShortDescription = product.ShortDescription;
            viewModel.Id = product.Id;
            viewModel.Name = product.Name;
            viewModel.Price = product.Price;
            viewModel.Images = product.Images;
            viewModel.IsAvailable = product.IsAvailable;
            viewModel.ProductBreadCrumbViewModels = product.BreadCrumb().ToList().ConvertAll(cat => new ProductBreadCrumbViewModel(){Id = cat.Id, Name = cat.Name});
            viewModel.Date = product.Date;

            viewModel.SKU = product.SKU;
            viewModel.Size = product.Size;
            viewModel.Color = product.Color;
            viewModel.Weight = product.Weight;
            viewModel.Country = product.Country;
            viewModel.IsVisible = product.IsVisible;
            viewModel.IsNew = product.IsNew;

            viewModel.Recomended = product.Recomended;

            return viewModel;
        }
Beispiel #10
0
        public virtual OrderLine AddOrderLine(Product product, int quantity, List<Outcome> outcomes)
        {
            OrderLine orderLine = new OrderLine(product, quantity, outcomes);
            orderLine.Price = product.Price;
            orderLine.ProductName = product.Name;

            Lines.Add(orderLine);
            return orderLine;
        }