示例#1
0
        public ActionResult StockListMovt(string itemNumber, string sessionId)
        {
            if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
            {
                using (var db = new InventoryDbContext())
                {
                    List <StockMovement> itemStockMovement =
                        db.stockmovements.Where(x => x.itemNumber == itemNumber).ToList();
                    ProductCatalogue pc = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault();

                    ViewData["itemNumber"] = itemNumber;
                    ViewData["itemDesc"]   = pc.description;
                    ViewData["uom"]        = pc.unitofmeasure;
                    ViewData["smt"]        = itemStockMovement;
                    ViewData["staffname"]  = userServices.getUserBySessionId(sessionId).employee.empName;
                    ViewData["sessionId"]  = sessionId;

                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
示例#2
0
        public void provide_cost_of_given_product(string productName)
        {
            var productCatalogue = new ProductCatalogue();

            Product productFromCatalogue = productCatalogue.Get(productName);

            Assert.Equal(productName, productFromCatalogue);
        }
示例#3
0
 public static ProductCatalogue GetProductByItemNumber(String itemNumber)
 {
     using (var db = new InventoryDbContext())
     {
         ProductCatalogue product = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault();
         return(product);
     }
 }
示例#4
0
        public Warehouse(int id, string country)
        {
            this.id      = id;
            this.country = country;
            int stock = id == -1 ? 0 : BaseStock;

            catalogue = new ProductCatalogue(stock);
        }
示例#5
0
        public ActionResult updateInventory(FormCollection formcollection, string itemNumber, string reason, string sessionId)
        {
            if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
            {
                using (var db = new InventoryDbContext())
                {
                    ProductCatalogue a  = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault();
                    ProductSupplier  ps = db.productSuppliers.Where(x => x.itemNumber == a.itemNumber).FirstOrDefault();
                    int adjqty          = int.Parse(formcollection[itemNumber + "-adjqty"]);
                    if (adjqty < 0)
                    {
                        if (System.Math.Abs(adjqty) > a.quantity)
                        {
                            return(RedirectToAction("StockList", "Store", new { sessionId, msg = "*Quantity cannot diminish to less than 0.*" }));
                        }
                        else
                        {
                            Voucher v = new Voucher();
                            v.quantityAdjusted = adjqty;
                            v.status           = "Pending";
                            v.voucherDate      = DateTime.Now;
                            v.itemNumber       = itemNumber;
                            v.itemName         = a.description;
                            v.price            = ps.price * System.Math.Abs(v.quantityAdjusted);
                            v.reason           = reason;
                            db.vouchers.Add(v);
                        }
                    }


                    ProductCatalogue pc = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault();
                    StockMovement    sm = new StockMovement();
                    if (adjqty < 0)
                    {
                        sm.movementDescription = "Manual Stock Adjustment";
                    }
                    else
                    {
                        sm.movementDescription = "Delivery from supplier";
                    }
                    sm.movementDate     = DateTime.Now;
                    sm.movementQuantity = adjqty;
                    sm.movementBalance  = adjqty + pc.quantity;
                    sm.itemNumber       = itemNumber;
                    db.stockmovements.AddOrUpdate(sm);
                    db.SaveChanges();


                    a.quantity = a.quantity + adjqty;
                    db.SaveChanges();
                    return(RedirectToAction("StockList", new { sessionId }));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
示例#6
0
 public ActionResult Requisitions(string sessionId, string msg)
 {
     if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
     {
         PendingItemsModel retrieval             = new PendingItemsModel();
         List <int>        matchingItemInventory = new List <int>();
         string            requisitionnumbers    = "";
         using (var db = new InventoryDbContext())
         {
             List <Requisition> pendingReqs = db.requisitions.Where(x => x.status == "Approved").ToList();
             //sort earliest first
             pendingReqs.Sort();
             pendingReqs.Reverse();
             //use requisitions to create a list of all requisitions to find sum of all items and their quantities
             foreach (Requisition requisition in pendingReqs)
             {
                 //add requisition to string of requisition numbers
                 if (requisitionnumbers == "")
                 {
                     requisitionnumbers = requisitionnumbers + requisition.reqformNumber;
                 }
                 else
                 {
                     requisitionnumbers = requisitionnumbers + "," + requisition.reqformNumber;
                 }
                 //add product request from requisition to pending product model
                 List <ProductCatalogue> productCatalogues = db.productCatalogues.ToList();
                 foreach (ProductReq productReq in requisition.productReqs)
                 {
                     ProductCatalogue pc = productCatalogues.Where(x => x.itemNumber == productReq.productitemnumber)
                                           .FirstOrDefault();
                     string location = pc.location;
                     string unit     = pc.unitofmeasure;
                     retrieval.add(productReq.productitemnumber, productReq.productDesc, unit,
                                   productReq.quantity, location);
                 }
             }
             for (int i = 0; i < retrieval.itemName.Count(); i++)
             {
                 //for each item, find its corresponding inventory stock amount
                 string           itemNumber = retrieval.itemNumber[i];
                 ProductCatalogue p          = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault();
                 matchingItemInventory.Add(p.quantity);
             }
         }
         ViewData["itemInventory"] = matchingItemInventory;
         ViewData["sessionId"]     = sessionId;
         ViewData["requisitions"]  = requisitionnumbers;
         ViewData["msg"]           = msg;
         ViewData["staffname"]     = userServices.getUserBySessionId(sessionId).employee.empName;
         return(View(retrieval));
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
示例#7
0
        public IActionResult getRelatedItems(int ProductId)

        {
            var relatedTags = new List <RelatedTag>();
            var result      = from prt in db.ProductRelatedTagMap
                              where prt.ProductId == ProductId
                              join rt in db.RelatedTag on prt.RelatedTagId equals rt.Id
                              where rt.IsActive == true
                              select rt;

            relatedTags = result.ToList();
            var tags      = db.Tag.Where(x => x.IsActive == true).Include(x => x.ProductTags).ToList();
            var finaltags = new List <Tag>();

            foreach (var t in relatedTags)
            {
                finaltags.AddRange(tags.Where(x => x.Name.ToLower().Trim() == t.Name.ToLower().Trim()).ToList());
            }
            var final = new List <ProductTag>();
            var all   = db.ProductTag.Where(x => x.IsActive == true && x.IsApproved == true).ToList();

            foreach (var f in finaltags)
            {
                final.AddRange(all.Where(x => x.TagId == f.Id).ToList());
            }
            var finalpro = new List <ProductCatalogue>();

            final = final.Where(x => x.ProductId != ProductId).ToList();
            foreach (var l in final)
            {
                var one     = new ProductCatalogue();
                var variant = db.ProductVariantDetails.Where(x => x.IsActive == true && x.ProductId == l.ProductId).FirstOrDefault();
                var varlist = new List <ProductVariantDetail>();

                if (variant != null)
                {
                    varlist.Add(variant);

                    varlist                = DealHelper.calculateDeal(varlist, db);
                    varlist                = PriceIncrementHelper.calculatePrice(varlist, db);
                    variant                = varlist[0];
                    one.Id                 = l.ProductId;
                    one.Name               = db.Products.Where(x => x.Id == l.ProductId).FirstOrDefault().Name;
                    one.CostPrice          = variant.CostPrice;
                    one.Discount           = variant.Discount;
                    one.PriceAfterDiscount = variant.PriceAfterdiscount;
                    one.SellingPrice       = variant.Price;
                    var image = db.ProductImages.Where(x => x.IsActive == true && x.IsDefault == true && x.ProductVariantDetailId == variant.Id).Select(x => x.ImagePath150x150).FirstOrDefault();
                    one.Image150 = image == null?db.ProductImages.Where(x => x.IsActive == true && x.ProductVariantDetailId == variant.Id).Select(x => x.ImagePath150x150).FirstOrDefault() : image;

                    one.InStock         = variant.InStock;
                    one.VariantDetailId = variant.Id;
                    finalpro.Add(one);
                }
            }
            return(Ok(finalpro.Take(20).ToList()));
        }
        public ActionResult Others2(string sessionId)
        {
            if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
            {
                using (var db = new InventoryDbContext())
                {
                    List <Requisition> req = new List <Requisition>();
                    req = db.requisitions.ToList();
                    List <Requisition> requ = new List <Requisition>();
                    List <Department>  dp   = new List <Department>();
                    dp = db.departments.ToList();
                    ProductCatalogue pc         = new ProductCatalogue();
                    List <double>    total      = new List <double>();
                    List <string>    department = new List <string>();
                    ProductSupplier  ps         = new ProductSupplier();
                    double           totalprice = 0;
                    foreach (var dps in dp)
                    {
                        foreach (var reqs in req)
                        {
                            if (dps.id == reqs.department)
                            {
                                if (reqs.status == "approved" || reqs.status == "partial")
                                {
                                    if (reqs.datecompleted != null && reqs.datecompleted.Value.Month == DateTime.Now.AddMonths(-1).Month&& reqs.datecompleted.Value.Year == DateTime.Now.Year)
                                    {
                                        requ.Add(reqs);
                                    }
                                }
                            }
                        }
                        foreach (var requs in requ)
                        {
                            foreach (var productReq in requs.productReqs)
                            {
                                pc         = db.productCatalogues.Where(x => x.itemNumber == productReq.productitemnumber).FirstOrDefault();
                                ps         = db.productSuppliers.Where(x => x.itemNumber == productReq.productitemnumber && x.preference == 1).FirstOrDefault();
                                totalprice = totalprice + pc.quantity * ps.price;//I can't find the supplier in Requisition and ProductReq model, so i can't get the price, just add one temperory¡£
                            }
                        }
                        total.Add(totalprice);
                        department.Add(dps.departmentName);
                    }
                    ViewData["total"]      = total;
                    ViewData["department"] = department; User user = db.users.Where(x => x.sessionId == sessionId).First();
                    ViewData["staffname"]  = user.employee.empName;
                    ViewData["sessionId"]  = sessionId;

                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
        public async Task <IActionResult> PutProductCatalogueItem(long id, ProductCatalogue Item)
        {
            if (id != Item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
示例#10
0
        public ViewResult Index(int page = 1)
        {
            var tempProducts = productService.GetProducts();

            var products = tempProducts.OrderBy(x => x.Id).Skip((page - 1) * PageSize).Take(PageSize);

            PagingInfo pagingInfo = new PagingInfo {
                CurrentPage = page, ItemsPerPage = PageSize, TotalItems = tempProducts.Count()
            };

            ProductCatalogue model = new ProductCatalogue {
                Products = products, PagingInfo = pagingInfo
            };

            return(View(model));
        }
示例#11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            productCatalogue =
                ProductCatalogue.GetCatalogues()
                .FirstOrDefault(x => x.Id == Request.QueryString["Id"]);
            if (productCatalogue == null)
            {
                return;
            }

            ProductCatalogueNameLabel.InnerText = productCatalogue.Name;
            if (!IsPostBack)
            {
                CatalogueEntriesListView.DataSource = productCatalogue.CatalogueEntries;
                CatalogueEntriesListView.DataBind();
            }
        }
 public ActionResult CatalogueEdit(int id, string sessionId)
 {
     if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
     {
         using (var db = new InventoryDbContext())
         {
             ProductCatalogue p = db.productCatalogues.Where(d => d.id == id).FirstOrDefault();
             ViewData["p"]         = p;
             ViewData["sessionId"] = sessionId;
             return(View());
         }
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
示例#13
0
        public ViewResult GetCatalogue(string category = null, int page = 1)
        {
            int productTypeId = productTypeService.GetProductTypeId(category);

            var tempProducts = productService.GetProducts(productTypeId);

            var products = tempProducts.OrderBy(x => x.Id).Skip((page - 1) * PageSize).Take(PageSize);

            PagingInfo pagingInfo = new PagingInfo {
                CurrentPage = page, ItemsPerPage = PageSize, TotalItems = tempProducts.Count()
            };

            ProductCatalogue model = new ProductCatalogue {
                Products = products, PagingInfo = pagingInfo, CurrentCategory = category
            };

            return(View(model));
        }
示例#14
0
        public void CanPaginate()
        {
            // Организация (arrange)
            ProductController controller = new ProductController(mock.Object, mockType.Object);

            controller.PageSize = 3;

            // Действие (act)
            ProductCatalogue result = (ProductCatalogue)((ViewResult)controller.GetCatalogue(null, 3)).Model;

            // Утверждение (assert)
            List <Product> products = result.Products.ToList();

            Assert.IsTrue(products.Count == 3);
            Assert.AreEqual(products[0].Name, "Product7");
            Assert.AreEqual(products[1].Name, "Product8");
            Assert.AreEqual(products[2].Name, "Product9");
        }
示例#15
0
        public void CanSendPaginationViewModel()
        {
            // Организация (arrange)
            ProductController controller = new ProductController(mock.Object, mockType.Object);

            controller.PageSize = 3;

            // Act
            ProductCatalogue result = (ProductCatalogue)((ViewResult)controller.GetCatalogue(category: null, page: 2)).Model;

            // Assert
            PagingInfo pageInfo = result.PagingInfo;

            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 9);
            Assert.AreEqual(pageInfo.TotalPages, 3);
        }
        public ActionResult InsertCatalogue(ProductCatalogue p, string sessionId)
        {
            if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
            {
                using (var db = new InventoryDbContext())
                {
                    //initiate quantity at zero
                    p.quantity = 0;
                    db.productCatalogues.Add(p);

                    db.SaveChanges();
                }
                return(RedirectToAction("Catalogue", new { sessionId }));
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
 public ActionResult UpdateMovement(string itemNumber, int newqty)
 {
     using (var db = new InventoryDbContext())
     {
         Inventory        a  = db.inventories.Where(x => x.itemNumber == itemNumber).FirstOrDefault();
         ProductCatalogue pc = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault();
         StockMovement    sm = new StockMovement();
         sm.movementDate = DateTime.Now;
         //sm.movementDescription = pc.supplier1;
         sm.movementQuantity = newqty - a.quantity;
         sm.movementBalance  = newqty;
         sm.itemNumber       = itemNumber;
         db.stockmovements.Add(sm);
         a.quantity  = newqty;
         pc.quantity = newqty;
         db.SaveChanges();
         ViewData["pc"] = pc;
         return(RedirectToAction("Stocklist"));
     }
 }
 public void InsertorUpdate(ProductCatalogue input)
 {
     using (var transactiobn = _dbContext.Database.BeginTransaction())
     {
         try
         {
             if (input != null)
             {
                 if (input.Id == 0)
                 {
                     _dbContext.ProductCatalogue.Add(new ProductCatalogue
                     {
                         Descriptions = input.Descriptions,
                         Image        = input.Image,
                         Name         = input.Name,
                         Price        = input.Price
                     });
                 }
                 else
                 {
                     var productData = _dbContext.ProductCatalogue.FirstOrDefault(x => x.Id == input.Id);
                     if (productData != null)
                     {
                         productData.Image        = input.Image != null ? input.Image : productData.Image;
                         productData.Price        = input.Price;
                         productData.Name         = input.Name;
                         productData.Descriptions = input.Descriptions;
                         _dbContext.Update(productData);
                     }
                 }
                 _dbContext.SaveChanges();
                 transactiobn.Commit();
             }
         }
         catch (Exception ex)
         {
             transactiobn.Dispose();
             throw ex;
         }
     }
 }
        public ActionResult Index()
        {
            if (!isCreated)
            {
                productCatalogue = ProductCatalogue.Random();
            }
            isCreated = true;
            var productCatalogueViewModel = new ProductCatalogueViewModel()
            {
                CatalogueName = productCatalogue.Name, CatalogueEntries = new List <EntryEditModel>()
            };

            foreach (var entry in productCatalogue.CatalogueEntries)
            {
                productCatalogueViewModel.CatalogueEntries.Add(
                    new EntryEditModel(entry)
                    );
            }

            return(View("Index", productCatalogueViewModel));
        }
        public ActionResult DeleteCatalogue(int id, string sessionid)
        {
            if (sessionid != null && userServices.getUserCountBySessionId(sessionid) == true)
            {
                using (var db = new InventoryDbContext())
                {
                    ProductCatalogue pdtcat = db.productCatalogues.Where(x => x.id == id).FirstOrDefault();
                    db.users.Where(x => x.sessionId == sessionid).FirstOrDefault();
                    Session["sessionid"] = sessionid;
                    db.productCatalogues.Remove(pdtcat);
                    db.SaveChanges();
                }

                return(RedirectToAction("Catalogue", new { sessionid }));
            }

            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
        public ActionResult CatalogueNew(string sessionId)
        {
            if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
            {
                ProductCatalogue p = new ProductCatalogue();

                using (var db = new InventoryDbContext())
                {
                    List <ProductCatalogue> catalogue = db.productCatalogues.ToList();

                    ViewData["Catalogue"] = catalogue;
                    ViewData["sessionId"] = sessionId;
                    ViewData["staffname"] = userServices.getUserBySessionId(sessionId).employee.empName;
                    ViewData["p"]         = p;
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
示例#22
0
 public ActionResult DBDeptStaff(string sessionId)
 {
     //as staff, main page to show current pending items and qty that are from requests that are not
     //cancelled, completed, or partialcomplete
     if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
     {
         using (var db = new InventoryDbContext())
         {
             User               user                   = db.users.Where(x => x.sessionId == sessionId).FirstOrDefault();
             String             department             = user.employee.departmentId;
             List <Requisition> departmentRequisitions = requestServices.getAllUncompleteRequisitions(department);
             departmentRequisitions.Sort();
             //use requisitions to create a list of all requisitions to find sum of all items and their quantities
             PendingItemsModel       pendingItems      = new PendingItemsModel();
             List <ProductCatalogue> productCatalogues = db.productCatalogues.ToList();
             foreach (Requisition requisition in departmentRequisitions)
             {
                 foreach (ProductReq productReq in requisition.productReqs)
                 {
                     ProductCatalogue pc       = productCatalogues.Where(x => x.itemNumber == productReq.productitemnumber).FirstOrDefault();
                     string           location = pc.location;
                     string           unit     = pc.unitofmeasure;
                     pendingItems.add(productReq.productitemnumber, productReq.productDesc, unit, productReq.quantity, location);
                 }
             }
             //sort pendingitems?
             ViewData["staffname"] = user.employee.empName;
             ViewData["sessionId"] = sessionId;
             return(View(pendingItems));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
示例#23
0
        private void ProductsActivity(object obj)
        {
            switch (obj as string)
            {
            case "ProdCatalogue":
            {
                ProductCatalogue catalogue = new ProductCatalogue();
                catalogue.Show();
            }
            break;

            case "ProdHSN":
            {
                ProductHSN hsn = new ProductHSN()
                {
                    DataContext = new HSNproductVM()
                };
                hsn.Show();
            }
            break;

            case "ProdCategory":
            {
                ProductCategory productCategory = new ProductCategory()
                {
                    DataContext = new ProductCategoryVM()
                };
                productCategory.Show();
            }
            break;

            default:
                MessageBox.Show("This is not supported in this version.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                break;
            }
        }
        public void VerifyProductCatalogue()
        {
            //Arrange
            ProductCatalogue Catalogue = new ProductCatalogue();
            List <IProduct>  Inventory = Catalogue.PopulateCatalogue();

            List <string> InventoryList = new List <string>();
            List <string> ItemNames     = new List <string>();

            //Act
            for (int i = 0; i < Inventory.Count; i++)
            {
                ItemNames.Add(Inventory[i].Name);
            }
            foreach (KeyValuePair <string, int> entry in Catalogue.productInventory)
            {
                InventoryList.Add(entry.Key);
            }
            //Assert
            for (int i = 0; i < Inventory.Count; i++)
            {
                Assert.AreEqual(InventoryList[i], ItemNames[i]);
            }
        }
 public ActionResult UpdateCatalogue(ProductCatalogue p, string sessionId)
 {
     if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
     {
         using (var db = new InventoryDbContext())
         {
             ProductCatalogue updatedCatalogue = db.productCatalogues.Where(x => x.id == p.id).FirstOrDefault();
             //updatedCatalogue.id = pcat.id;
             updatedCatalogue.itemNumber      = p.itemNumber;
             updatedCatalogue.category        = p.category;
             updatedCatalogue.description     = p.description;
             updatedCatalogue.reorderlevel    = p.reorderlevel;
             updatedCatalogue.reorderquantity = p.reorderquantity;
             updatedCatalogue.unitofmeasure   = p.unitofmeasure;
             db.productCatalogues.AddOrUpdate(updatedCatalogue);
             db.SaveChanges();
             return(RedirectToAction("Catalogue", new { sessionId }));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
示例#26
0
 public Retailer()
 {
     catalogue = new ProductCatalogue(1);
 }
 public void TestCleanUp()
 {
     m = null;
 }
 public void InitializeTest()
 {
     m = new ProductCatalogue();
 }
示例#29
0
        public List <ProductCatalogue> getFilterProducts([FromBody] Filter filter, [FromQuery] int page, [FromQuery] int pagesize)
        {
            try
            {
                if (filter.SearchData == "undefined" || filter.SearchData == null)
                {
                    filter.SearchData = "";
                }
                var model    = new List <ProductCatalogue>();
                var products = db.Products.Where(x => x.IsActive == true && x.IsEnable == true && x.ProductCategory.IsShow == true);
                var prodIds  = db.HomeCategoryProduct.Where(x => x.IsActive == true && x.HomeCategoryId == filter.CategoryId).Select(x => x.ProductId).ToList();
                var prod     = new List <Product>();

                decimal minprice = 0;
                decimal maxprice = 0;

                if (filter.SelectedVariants.Count() > 0)
                {
                    foreach (var s in filter.SelectedVariants)
                    {
                        var result = new List <Product>();
                        foreach (var o in s.VariantOptionId)
                        {
                            var pro = from cv in db.CategoryVariants
                                      where s.CategoryId == cv.ProductCategoryId && s.VariantId == cv.VariantId
                                      join pvo in db.ProductVariantOptions on cv.Id equals pvo.CategoryVariantId
                                      join pvd in db.ProductVariantDetails on pvo.ProductVariantDetailId equals pvd.Id
                                      join p in products on pvd.ProductId equals p.Id
                                      where o == pvo.VariantOptionId &&
                                      cv.IsActive == true && pvo.IsActive == true && pvd.IsActive == true && p.IsActive == true
                                      select p;
                            result.AddRange(pro.ToList());
                        }
                        products = result.AsQueryable();
                    }
                }
                var variantsData = new List <ProductVariantDetail>();
                foreach (var p in prodIds)
                {
                    if (products.Any(x => x.Id == p))
                    {
                        prod.Add(products.Where(x => x.Id == p).Include(x => x.ProductVariantDetails).FirstOrDefault());
                    }
                }
                foreach (var item in prod)
                {
                    if (item.ProductVariantDetails == null)
                    {
                        item.ProductVariantDetails = db.ProductVariantDetails.Where(x => x.ProductId == item.Id && x.IsActive == true).ToList();
                    }
                    var data = item.ProductVariantDetails.Where(b => b.IsActive == true).ToList();
                    variantsData.AddRange(data);
                }
                //variantsData.OrderByDescending(x => x.Id);
                var priceListdata = new List <ProductVariantDetail>();
                var plist         = prod.ToList();
                var variantlist   = db.ProductVariantDetails.Where(x => x.IsActive == true).Include(x => x.Product).ToList();
                foreach (var p in plist)
                {
                    var list = variantlist.Where(x => x.ProductId == p.Id).ToList();
                    priceListdata.AddRange(list);
                }
                //pricefilter
                var minprice1 = priceListdata.Count() == 0 ? 0 : priceListdata.Min(x => x.Price);
                var maxprice1 = priceListdata.Count() == 0 ? 0 : priceListdata.Max(x => x.Price);
                var pricelist = PriceRange(maxprice1, minprice1);

                var list1 = new List <ProductVariantDetail>();
                minprice = filter.MinPrice != "" && filter.MinPrice != "0" ? Convert.ToDecimal(filter.MinPrice.Split('$')[1]) : 0;
                maxprice = filter.MaxPrice != "" && filter.MaxPrice != "0" ? Convert.ToDecimal(filter.MaxPrice.Split('$')[1]) : 0;
                if (maxprice == 0)
                {
                    list1 = variantsData.Where(x => x.Price >= minprice).ToList();
                }
                else
                {
                    list1 = variantsData.Where(x => x.Price >= minprice && x.Price < maxprice).ToList();
                }
                //search by name
                //var data11 =
                foreach (var l in list1)
                {
                    if (l.Product == null)
                    {
                        l.Product = db.Products.Where(x => x.Id == l.ProductId && x.IsActive == true && x.IsEnable == true).FirstOrDefault();
                    }
                }

                //get data for page
                var final = list1.OrderByDescending(x => x.Id).Skip((page - 1) * pagesize).Take(pagesize).ToList();
                var count = list1.Count();

                var ProductVariantOptions = db.ProductVariantOptions.Where(b => b.IsActive == true).ToList();
                var optionsList           = db.VariantOptions.Where(b => b.IsActive == true).Include(x => x.Variant).ToList();

                var variantsList = new List <ProductVariantDetail>();
                final = DealHelper.calculateDeal(final, db);
                final = PriceIncrementHelper.calculatePrice(final, db);

                foreach (var p in final)
                {
                    var pro = new ProductCatalogue();
                    pro.Id = p.ProductId;
                    //pro.Name = p.Product.Name;
                    var pdata = prod.Where(x => x.Id == p.ProductId).FirstOrDefault();
                    pro.Name                = pdata?.Name;
                    pro.ShipmentVendor      = pdata?.ShipmentVendor ?? false;
                    pro.ShipmentCost        = pdata?.ShipmentCost ?? 0;
                    pro.ShipmentTime        = pdata?.ShipmentTime ?? 0;
                    pro.Description         = pdata?.Description;
                    pro.ProductCategoryName = pdata?.ProductCategory?.Name;
                    pro.ProductCategoryId   = Convert.ToInt32(pdata?.ProductCategoryId);

                    pro.InStock = p.InStock;

                    pro.VariantDetailId    = p.Id;
                    pro.Discount           = p.Discount;
                    pro.SellingPrice       = p.Price;
                    pro.PriceAfterDiscount = p.PriceAfterdiscount;
                    //}


                    var selectedImage = new ProductImage();
                    selectedImage = db.ProductImages.Where(x => x.IsActive == true && x.IsDefault == true && x.ProductVariantDetailId == p.Id).FirstOrDefault();
                    if (selectedImage == null)
                    {
                        selectedImage = db.ProductImages.Where(x => x.IsActive == true && x.ProductVariantDetailId == pro.VariantDetailId).FirstOrDefault();
                    }
                    pro.Image    = selectedImage?.ImagePath;
                    pro.Image150 = selectedImage?.ImagePath150x150;
                    pro.Image450 = selectedImage?.ImagePath450x450;

                    var VariantOptionIds = ProductVariantOptions.Where(x => x.ProductVariantDetailId == pro.VariantDetailId && x.IsActive == true).ToList().Select(x => x.VariantOptionId);
                    foreach (var v in VariantOptionIds)
                    {
                        var data = optionsList.Where(x => x.Id == v && x.IsActive == true).FirstOrDefault().RemoveReferences();
                        pro.VariantOptions.Add(data);
                    }
                    pro.Rating    = db.RatingReviews.Where(x => x.IsActive == true && x.ReviewStatusId == 1 && x.ProductId == p.ProductId).FirstOrDefault()?.Rating;
                    pro.Count     = count;
                    pro.PriceList = pricelist;
                    pro.AvgRate   = AvgRating(p.Id);
                    pro.ActiveTo  = p.ActiveTo;
                    if (pdata != null)
                    {
                        model.Add(pro);
                    }
                }


                //rate
                model = model.Where(x => x.AvgRate >= filter.AvgRate).OrderByDescending(x => x.Id).ToList();
                //sorting
                if (filter.SortBy == "HighToLow")
                {
                    model = model.OrderByDescending(x => x.PriceAfterDiscount).ToList();
                }
                else if (filter.SortBy == "LowToHigh")
                {
                    model = model.OrderBy(x => x.PriceAfterDiscount).ToList();
                }
                if (model.Count == 0)
                {
                    var model1 = new ProductCatalogue();
                    model1.PriceList = pricelist;
                    model.Add(model1);
                }

                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#30
0
        public async Task <IActionResult> GetLikeProducts(string IpAddress, int UserId)


        {
            var list = new List <ProductTag>();

            if (UserId > 0)
            {
                var result = from log in db.UserLogs
                             where log.IsActive == true && log.UserId == UserId && log.Url.Contains("product-details")
                             join tags in db.ProductTag on log.ProductId equals tags.ProductId
                             join p in db.Products on tags.ProductId equals p.Id
                             select tags;
                list = await result.ToListAsync();
            }
            else
            {
                var result = from log in db.UserLogs
                             where log.IsActive == true && (log.UserId == null || log.UserId == 0) && log.IPAddress == IpAddress && log.Url.Contains("product-details")
                             join tags in db.ProductTag on log.ProductId equals tags.ProductId
                             join p in db.Products on tags.ProductId equals p.Id
                             select tags;
                list = result.ToList();
            }
            var ids = list.Select(x => x.ProductId).Distinct();

            list = new List <ProductTag>();
            foreach (var l in ids)
            {
                list.AddRange(db.ProductTag.Where(x => x.ProductId == l).ToList());
            }
            var alltags   = db.ProductTag.Where(x => x.IsActive == true).ToList();
            var finaltags = new List <ProductTag>();

            foreach (var l in list)
            {
                var get = alltags.Where(x => x.TagId == l.TagId && x.ProductId != l.ProductId).ToList();
                finaltags.AddRange(get);
            }
            var final = new List <ProductCatalogue>();

            foreach (var l in finaltags)
            {
                var one     = new ProductCatalogue();
                var variant = db.ProductVariantDetails.Where(x => x.IsActive == true && x.ProductId == l.ProductId).FirstOrDefault();
                var varlist = new List <ProductVariantDetail>();

                if (variant != null)
                {
                    varlist.Add(variant);

                    varlist                = DealHelper.calculateDeal(varlist, db);
                    varlist                = PriceIncrementHelper.calculatePrice(varlist, db);
                    variant                = varlist[0];
                    one.Id                 = l.ProductId;
                    one.Name               = db.Products.Where(x => x.Id == l.ProductId).FirstOrDefault().Name;
                    one.CostPrice          = variant.CostPrice;
                    one.Discount           = variant.Discount;
                    one.PriceAfterDiscount = variant.PriceAfterdiscount;
                    one.SellingPrice       = variant.Price;
                    var image = db.ProductImages.Where(x => x.IsActive == true && x.IsDefault == true && x.ProductVariantDetailId == variant.Id).Select(x => x.ImagePath150x150).FirstOrDefault();
                    one.Image150 = image == null?db.ProductImages.Where(x => x.IsActive == true && x.ProductVariantDetailId == variant.Id).Select(x => x.ImagePath150x150).FirstOrDefault() : image;

                    one.InStock         = variant.InStock;
                    one.VariantDetailId = variant.Id;
                    final.Add(one);
                }
            }
            return(Ok(final.Take(20).ToList()));
        }