public static SkuStocksModel GetStockById(Guid Id)
        {
            DBContext      _context = new DBContext();
            SkuStocksModel stock    = StockMapper.Mapper(_context.Stocks.Include(x => x.Sku).Include(x => x.Seller).Where(x => x.Id == Id).SingleOrDefault());

            return(stock);
        }
        public IActionResult Upsert(SkuStocksModel stock)
        {
            DBContext     _context = new DBContext();
            LogController log      = new LogController();

            if (stock.Id == new Guid())
            {
                List <SkuStocksModel> stocks = GetAllStocks();
                SkuStocksModel        existe = stocks.Where(x => x.Seller.Id == stock.Seller.Id && x.Sku.Id == stock.Sku.Id).FirstOrDefault();
                if (existe != null)
                {
                    log.LogRegister(stock, "CreatedError", Models.Enums.LogTypeEnum.Stocks);
                    return(RedirectToAction("Index", stock.Seller.Id));
                }
                stock.Id         = Guid.NewGuid();
                stock.LastUpdate = DateTime.Now;
                log.LogRegister(stock, "Created", Models.Enums.LogTypeEnum.Stocks);
                _context.Stocks.Add(StockMapper.Mapper(stock));
            }
            else
            {
                stock.LastUpdate = DateTime.Now;
                _context.Stocks.Update(StockMapper.Mapper(stock));

                log.LogRegister(stock, "Updated", Models.Enums.LogTypeEnum.Stocks);
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", new { id = stock.Seller.Id }));
        }
        public static List <SkuStocksModel> GetAllStocksBySeller(Guid SellerId)
        {
            DBContext             _context = new DBContext();
            List <SkuStocksModel> stocks   = StockMapper.Mapper(_context.Stocks.Include(x => x.Sku).Include(x => x.Seller).Where(x => x.SellerId == SellerId).ToList());

            return(stocks);
        }
예제 #4
0
 public IntegrationItemsStockApp(IFactoryConnection efc)
 {
     _epr = new IntegrationItemsStockRepo(efc);
     _itemInputStockApp  = new ItemInputStockApp(efc);
     _itemOutputStockApp = new ItemOutputStockApp(efc);
     _stockMapper        = new StockMapper();
     _conn = efc;
 }
예제 #5
0
 public IntegrationCapeStockApp(IFactoryConnection efc)
 {
     _epr            = new IntegrationCapeStockRepo(efc);
     _inputStockApp  = new InputStockApp(efc);
     _outputStockApp = new OutputStockApp(efc);
     _stockMapper    = new StockMapper();
     _conn           = efc;
 }
예제 #6
0
 public Stock(StockMapper mapper, DataAccess.DataAccess dac, int id_stock, int id_product, DateTime expiration_date, string name_provider, int quantity_product) : this(mapper, dac)
 {
     this.id_stock         = id_stock;
     this.id_product       = id_product;
     this.expiration_date  = expiration_date;
     this.name_provider    = name_provider;
     this.quantity_product = quantity_product;
 }
예제 #7
0
 public EmployeeModel GetById(Guid id)
 {
     using (StockDbContext context = new StockDbContext())
         using (IUnitOfWork unitOfWork = new EfUnitOfWork(context))
         {
             var           employee      = unitOfWork.GetRepository <Employee>().GetById(id);
             EmployeeModel employeeModel = StockMapper.EmployeeModelMap(employee);
             return(employeeModel);
         }
 }
예제 #8
0
        public StockView()
        {
            var databaseContext = Application.Current.Properties["Workspace"] as IUnitOfWork;
            var stockList       = Task.Run(async() => await databaseContext.StockRepository.GetAll()).Result;

            Items = new ObservableCollection <StockViewModel>(StockMapper.DoListMap(stockList));
            InitializeComponent();

            MyListView.ItemsSource = Items;
        }
예제 #9
0
        public StockController()
        {
            string constr = GlobalData.connectionString;


            _dataAccess  = new DataAccess.DataAccess(constr);
            _stockMapper = new StockMapper(_dataAccess);

            //GetAirports();
        }
예제 #10
0
 public bool Delete(OrderModel entity)
 {
     using (StockDbContext context = new StockDbContext())
         using (IUnitOfWork unitOfWork = new EfUnitOfWork(context))
         {
             Order order = StockMapper.OrderMap(entity);
             unitOfWork.GetRepository <Order>().Delete(order);
             int saveCount = unitOfWork.SaveChanges();
             if (saveCount == 0)
             {
                 return(false);
             }
             return(true);
         }
 }
예제 #11
0
 public bool Delete(EmployeeModel entity)
 {
     using (StockDbContext context = new StockDbContext())
         using (IUnitOfWork unitOfWork = new EfUnitOfWork(context))
         {
             Employee employee = StockMapper.EmployeeMap(entity);
             unitOfWork.GetRepository <Employee>().Delete(employee);
             int saveCount = unitOfWork.SaveChanges();
             if (saveCount == 0)
             {
                 return(false);
             }
             return(true);
         }
 }
        public IActionResult Delete(Guid Id)
        {
            DBContext      _context = new DBContext();
            SkuStocksModel stock    = GetStockById(Id);

            _context.Stocks.Remove(StockMapper.Mapper(stock));

            LogController log = new LogController();

            log.LogRegister(stock, "Deleted", Models.Enums.LogTypeEnum.Stocks);

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #13
0
        /// <summary>
        /// saving the stock object.
        /// </summary>
        /// <param name="stockDto">stock object that want to save.</param>
        /// <returns>saved stock object</returns>
        public Domain.Stock.Model.Stock SaveStock(StockDto stockDto)
        {
            StockValidator validator   = new StockValidator();
            bool           isValid     = validator.IsPostValid(stockDto);
            StockMapper    modelMapper = new StockMapper();

            Domain.Stock.Model.Stock stockEntity = modelMapper.EntityFrom(stockDto);
            if (!isValid || stockEntity == null)
            {
                throw new NullReferenceException();
            }

            IList <Domain.Products.Model.Product> productEntities = modelMapper.ProductDtoFrom(stockDto);

            stockEntity.CreatedOn = DateTime.Now;
            Domain.Stock.Model.Stock result = this._stockRepository.SaveStock(stockEntity, productEntities);
            return(stockEntity);
        }
예제 #14
0
 public bool Update(ProductModel entity)
 {
     try
     {
         using (StockDbContext context = new StockDbContext())
             using (IUnitOfWork unitofwork = new EfUnitOfWork(context))
             {
                 Product product = StockMapper.ProductMap(entity);
                 unitofwork.GetRepository <Product>().Update(product);
                 int saveCount = unitofwork.SaveChanges();
                 if (saveCount == 0)
                 {
                     return(false);
                 }
                 return(true);
             }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw;
     }
 }
예제 #15
0
 public bool Delete(CategoryModel entity)
 {
     try
     {
         using (StockDbContext context = new StockDbContext())
             using (IUnitOfWork unitofwork = new EfUnitOfWork(context))
             {
                 Category category = StockMapper.CategoryMap(entity);
                 unitofwork.GetRepository <Category>().Delete(category);
                 int saveCount = unitofwork.SaveChanges();
                 if (saveCount == 0)
                 {
                     return(false);
                 }
                 return(true);
             }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw;
     }
 }
        public async Task <string> AddItemToCart(string skuId)
        {
            var buyer = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (buyer != null)
            {
                DBContext _context = new DBContext();

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

                SkuStocksModel stock = StockMapper.Mapper(_context.Stocks.Include(x => x.Seller).Include(x => x.Sku).Where(x => x.SellerId == order.Seller.Id && x.Sku.Id == Guid.Parse(skuId)).FirstOrDefault());

                if (stock != null)
                {
                    OrderItemsModel item = OrderItemsMapper.Mapper(_context.OrderItems.Include(x => x.Sku).Include(x => x.Seller).Include(x => x.Order).Where(x => x.SkuId == Guid.Parse(skuId) && x.OrderId == order.Id).FirstOrDefault());

                    if (item == null)
                    {
                        item          = new OrderItemsModel();
                        item.Id       = Guid.NewGuid();
                        item.Seller   = order.Seller;
                        item.Sku      = stock.Sku;
                        item.Order    = order;
                        item.Quantity = 1;
                        _context.Add(OrderItemsMapper.Mapper(item));

                        var currentOrder = _context.Order.Find(order.Id);
                        currentOrder.SubTotal += item.Sku.Price;
                        currentOrder.Total    += item.Sku.Price;

                        _context.Update(currentOrder);
                    }
                    else
                    {
                        var currentItem = _context.OrderItems.Find(item.Id);
                        currentItem.Id        = item.Id;
                        currentItem.OrderId   = order.Id;
                        currentItem.Quantity += 1;
                        currentItem.SellerId  = order.Seller.Id;
                        currentItem.SkuId     = stock.Sku.Id;

                        _context.Update(currentItem);

                        var currentOrder = _context.Order.Find(order.Id);
                        currentOrder.SubTotal += item.Sku.Price;
                        currentOrder.Total    += item.Sku.Price;

                        _context.Update(currentOrder);
                    }

                    var newstock = _context.Stocks.Find(stock.Id);
                    newstock.Id                 = stock.Id;
                    newstock.SellerId           = order.Seller.Id;
                    newstock.SkuId              = stock.Sku.Id;
                    newstock.AvailableQuantity -= 1;
                    newstock.LastUpdate         = DateTime.Now;

                    _context.Update(newstock);
                    _context.SaveChanges();
                    return("OK");
                }
                return("ESSE PRODUTO NÃO TEM ESTOQUE PARA O LOJISTA SELECIONADO");
            }
            else
            {
                return("FAIL");
            }
        }
예제 #17
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"));
        }
예제 #18
0
 public Stock(StockMapper mapper, DataAccess.DataAccess dac)
 {
     _mapper     = mapper;
     _dataAccess = dac;
 }