Пример #1
0
        public List <SelectListItem> GetCategoriesSelectedList(int?selectedItemId = null)
        {
            try
            {
                List <SelectListItem> list = new List <SelectListItem>();
                var categories             = _categoriesRepository.Get().ToList();

                foreach (var category in categories)
                {
                    var selected = category.CategoryId == selectedItemId;
                    list.Add(new SelectListItem
                    {
                        Value    = category.CategoryId.ToString(),
                        Text     = category.CategoryName,
                        Selected = selected
                    });
                }

                return(list);
            }
            catch (Exception e)
            {
                Log.Error("Category service error!" + Environment.NewLine + $"{e}");
                throw;
            }
        }
Пример #2
0
        public List <SelectListItem> GetSuppliersSelectedList(int?selectedItemId = null)
        {
            try
            {
                List <SelectListItem> list = new List <SelectListItem>();
                var suppliers = _supplierRepository.Get().ToList();

                foreach (var supplier in suppliers)
                {
                    var selected = supplier.SupplierId == selectedItemId;
                    list.Add(new SelectListItem
                    {
                        Value    = supplier.SupplierId.ToString(),
                        Text     = supplier.CompanyName,
                        Selected = selected
                    });
                }

                return(list);
            }
            catch (Exception e)
            {
                Log.Error("Supplier service error!" + Environment.NewLine + $"{e}");
                throw;
            }
        }
Пример #3
0
        public void DeleteProduct(int id)
        {
            try
            {
                var orderDetails = _orderDetailsRepository.Get().Where(x => x.ProductId == id);
                foreach (var detail in orderDetails)
                {
                    _orderDetailsRepository.Delete(detail.OrderId, id);
                }

                _productsRepository.Delete(id);
            }
            catch (Exception e)
            {
                Log.Error("Product service error!" + Environment.NewLine + $"{e}");
                throw;
            }
        }
        public IEnumerable <TGameStoreEntity> Get()
        {
            var gameStoreEntities = _gameStoreRepository.Get().ToList();

            gameStoreEntities.ForEach(_ => _.Id = DbIdentifier.EncodeId(_.Id, DbType.GameStore));

            var northwindEntities = Mapper.Map <List <TGameStoreEntity> >(_northwindRepository.Get()).ToList();

            //northwindEntities.ForEach(_ => _.Id = DbIdentifier.EncodeId(_.Id, DbType.Northwind));

            northwindEntities.ForEach(
                x =>
            {
                if (!gameStoreEntities.Select(z => z.Id).Contains(x.Id))
                {
                    gameStoreEntities.Add(x);
                }
            });

            return(gameStoreEntities.Where(_ => _.IsDeleted == false).ToList());
        }
Пример #5
0
        public List <ProductsModel> GetProducts()
        {
            try
            {
                var categories = _categoriesRepository.Get();
                var suppliers  = _supplierRepository.Get();
                var products   = _productsRepository.Get();

                return(products.Select(p => new ProductsModel
                {
                    Discontinued = p.Discontinued,
                    ReorderLevel = p.ReorderLevel,
                    ProductId = p.ProductId,
                    ProductName = p.ProductName,
                    QuantityPerUnit = p.QuantityPerUnit,
                    UnitPrice = p.UnitPrice,
                    UnitsInStock = p.UnitsInStock,
                    UnitsOnOrder = p.UnitsOnOrder,
                    Category = categories.Where(c => c.CategoryId == p.CategoryId).Select(nc => new CategoriesModel()
                    {
                        CategoryId = nc.CategoryId,
                        CategoryName = nc.CategoryName
                    }).FirstOrDefault(),
                    Supplier = suppliers.Where(s => s.SupplierId == p.SupplierId).Select(ns => new SuppliersModel()
                    {
                        SupplierId = ns.SupplierId,
                        CompanyName = ns.CompanyName
                    }).FirstOrDefault()
                }).Take(_productsSettings.Maximum == 0 ? products.ToList().Count : _productsSettings.Maximum)
                       .ToList());
            }
            catch (Exception e)
            {
                Log.Error("Product service error!" + Environment.NewLine + $"{e}");
                throw;
            }
        }