Ejemplo n.º 1
0
        public static ShowcaseModel GetShowcaseById(Guid showcaseId)
        {
            DBContext     _context = new DBContext();
            ShowcaseModel showcase = ShowcaseMapper.Mapper(_context.Showcases.Where(x => x.Id == showcaseId).FirstOrDefault());

            showcase.ShowcaseItems = ShowcaseItemsMapper.Mapper(_context.ShowcaseItems.Where(x => x.ShowCaseId == showcaseId).Include(x => x.Sku).Include(x => x.ShowCase).ToList());
            return(showcase);
        }
Ejemplo n.º 2
0
        public static List <ShowcaseModel> GetAllAvailableShowcases()
        {
            DBContext            _context  = new DBContext();
            List <ShowcaseModel> showcases = ShowcaseMapper.Mapper(_context.Showcases.Where(x => x.StartDate <= DateTime.Now && x.EndDate >= DateTime.Now).ToList());

            foreach (var item in showcases)
            {
                item.ShowcaseItems = ShowcaseItemsMapper.Mapper(_context.ShowcaseItems.Where(y => y.ShowCaseId == item.Id).Include(x => x.Sku).ToList());
                foreach (var sku in item.ShowcaseItems)
                {
                    sku.Sku.Product = ProductMapper.Mapper(_context.Products.Where(x => x.Id == sku.Sku.ProductId).FirstOrDefault());
                }
            }

            return(showcases);
        }
Ejemplo n.º 3
0
        public IActionResult Upsert(ShowcaseModel sc)
        {
            var       SkuCodes = sc.ShowCaseItemCodes.Split("\r\n");
            DBContext _context = new DBContext();

            if (sc.Id == new Guid())
            {
                sc.Id = Guid.NewGuid();
                _context.Showcases.Add(ShowcaseMapper.Mapper(sc));

                foreach (var item in SkuCodes)
                {
                    ShowcaseItemsModel scs = new ShowcaseItemsModel();
                    scs.ShowCase = sc;
                    scs.Sku      = SkuMapper.Mapper(_context.Skus.Where(x => x.Barcode == item).FirstOrDefault());
                    _context.ShowcaseItems.Add(ShowcaseItemsMapper.Mapper(scs));
                }

                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public IActionResult Carregar()
        {
            var       buyer    = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            DBContext _context = new DBContext();

            OrderModel validacao = OrderMapper.Mapper(_context.Order.Include(x => x.Address).Include(x => x.Buyer).Include(x => x.Seller).Where(x => x.BuyerId == Guid.Parse(buyer)).FirstOrDefault());

            if (validacao == null)
            {
                ProductModel p1 = new ProductModel
                {
                    Id          = Guid.NewGuid(),
                    Code        = "0001",
                    Name        = "Coca-Cola",
                    Description = "Refrigerante",
                    ImageUrl    = "https://i.imgur.com/ps6alt2.jpg",
                    Skus        = new List <SkuModel>()
                };

                SkuModel s1 = new SkuModel
                {
                    Id      = Guid.NewGuid(),
                    Barcode = "793001215",
                    Name    = "350 ml",
                    Color   = "#ff0000",
                    Price   = 4.50
                };

                SkuModel s2 = new SkuModel
                {
                    Id       = Guid.NewGuid(),
                    Barcode  = "793001216",
                    Name     = "2 L",
                    Color    = "#ff0000",
                    ImageUrl = "https://i.imgur.com/ps6alt2.jpg",
                    Price    = 7.00
                };

                p1.Skus.Add(s1);
                p1.Skus.Add(s2);

                _context.Products.Add(ProductMapper.Mapper(p1));

                ProductModel p2 = new ProductModel
                {
                    Id          = Guid.NewGuid(),
                    Name        = "Fanta Laranja",
                    Code        = "0002",
                    Description = "Refri de laranja",
                    ImageUrl    = "https://i.imgur.com/cxKXQ0k.png",
                    Skus        = new List <SkuModel>()
                };

                SkuModel s3 = new SkuModel
                {
                    Id       = Guid.NewGuid(),
                    Name     = "350 ml",
                    Barcode  = "79300251362",
                    Price    = 4.50,
                    Color    = "#f24f00",
                    ImageUrl = "https://i.imgur.com/cxKXQ0k.png"
                };

                p2.Skus.Add(s3);

                _context.Products.Add(ProductMapper.Mapper(p2));

                UserModel u = new UserModel
                {
                    Id            = Guid.NewGuid(),
                    FullName      = "Shopping Palladium",
                    Document      = "08355847000109",
                    Discriminator = Models.Enums.DiscriminatorEnum.Seller
                };

                _context.Users.Add(UserMapper.Mapper(u));

                SkuStocksModel ss = new SkuStocksModel
                {
                    Id = Guid.NewGuid(),
                    AvailableQuantity = 52,
                    LastUpdate        = DateTime.Now,
                    Sku    = s2,
                    Seller = u
                };

                SkuStocksModel ss2 = new SkuStocksModel
                {
                    Id = Guid.NewGuid(),
                    AvailableQuantity = 31,
                    LastUpdate        = DateTime.Now,
                    Sku    = s3,
                    Seller = u
                };

                _context.Stocks.Add(StockMapper.Mapper(ss));
                _context.Stocks.Add(StockMapper.Mapper(ss2));

                ShowcaseModel sc = new ShowcaseModel
                {
                    Id         = Guid.NewGuid(),
                    Name       = "Inverno",
                    StartDate  = DateTime.Now,
                    EndDate    = DateTime.Now,
                    LastUpdate = DateTime.Now
                };

                ShowcaseItemsModel scp1 = new ShowcaseItemsModel()
                {
                    Id       = Guid.NewGuid(),
                    ShowCase = sc,
                    Sku      = s2
                };

                ShowcaseItemsModel scp2 = new ShowcaseItemsModel()
                {
                    Id       = Guid.NewGuid(),
                    ShowCase = sc,
                    Sku      = s3
                };

                ShowcaseItemsMapper.Mapper(scp1);
                ShowcaseItemsMapper.Mapper(scp2);

                _context.Showcases.Add(ShowcaseMapper.Mapper(sc));
                _context.ShowcaseItems.Add(ShowcaseItemsMapper.Mapper(scp1));
                _context.ShowcaseItems.Add(ShowcaseItemsMapper.Mapper(scp2));

                AddressModel address = new AddressModel
                {
                    Id = Guid.NewGuid()
                };

                _context.Add(AddressMapper.Mapper(address));

                PaymentModel payment = new PaymentModel
                {
                    Id = Guid.NewGuid()
                };

                _context.Add(PaymentMapper.Mapper(payment));

                OrderModel order = new OrderModel
                {
                    Id           = Guid.NewGuid(),
                    CreateDate   = DateTime.Now,
                    Discount     = 0,
                    SubTotal     = 0,
                    Total        = 0,
                    FriendlyCode = "S&T-X3VI5A",
                    Buyer        = new UserModel
                    {
                        Id = Guid.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier)),
                    },
                    Seller = new UserModel
                    {
                        Id = u.Id,
                    },
                    Address = address,
                    Payment = payment
                };

                _context.Order.Add(OrderMapper.Mapper(order));

                _context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }