Пример #1
0
 public IActionResult Add(ProductCategoryCommission model)
 {
     model.IsActive = true;
     try
     {
         db.ProductCategoryCommission.Add(model);
         db.SaveChanges();
         obj.CategoryCommissions = null;
         return(Ok(true));
     }
     catch (Exception ex)
     {
         return(Ok(false));
     }
 }
Пример #2
0
        public static List <ProductVariantDetail> calculateDealonetime(List <ProductVariantDetail> Data, int DealId, PistisContext db)
        {
            var finaldDeal = deals(db);
            var dealpro    = new List <DealProduct>();

            dealpro = finaldDeal.Where(x => x.Id == DealId).SelectMany(x => x.DealProduct).ToList();
            var commission        = new ProductCategoryCommission();
            var productCategoryId = 0;

            foreach (var d in Data)
            {
                var ProductCategoryId = db.Products.Where(x => x.Id == d.ProductId).FirstOrDefault().ProductCategoryId;
                var productCategory   = db.ProductCategories.Where(x => x.Id == ProductCategoryId).FirstOrDefault();
                if (productCategory != null)
                {
                    if (productCategory.ParentId == null)
                    {
                        productCategoryId = productCategory.Id;
                    }
                    else
                    {
                        productCategory = db.ProductCategories.Where(x => x.Id == productCategory.ParentId).FirstOrDefault();
                        if (productCategory.ParentId == null)
                        {
                            productCategoryId = productCategory.Id;
                        }
                        else
                        {
                            productCategory   = db.ProductCategories.Where(x => x.Id == productCategory.ParentId).FirstOrDefault();
                            productCategoryId = productCategory.Id;
                        }
                    }
                }
                if (productCategoryId > 0)
                {
                    var obj = new CategoryCommission(db);
                    commission = obj.CategoryCommissions.Where(x => x.IsActive == true && x.ProductCategoryId == productCategoryId).FirstOrDefault();
                    if (commission == null)
                    {
                        commission            = new ProductCategoryCommission();
                        commission.Commission = 0;
                    }
                }



                if (dealpro.Any(z => z.ProductVariantId == d.Id))
                {
                    foreach (var p in dealpro.Where(z => z.ProductVariantId == d.Id))
                    {
                        d.Discount = d.Discount + Convert.ToInt32(p.Deal.Discount);
                        var priceaftercomm = d.Price + (d.Price * commission.Commission / 100);
                        d.Price = priceaftercomm;
                        d.PriceAfterdiscount = (priceaftercomm - (priceaftercomm * d.Discount / 100));
                        d.ActiveTo           = p.Deal.ActiveTo;
                    }
                }
                else
                {
                    d.Discount = d.Discount;
                    var priceaftercomm = d.Price + (d.Price * commission.Commission / 100);
                    d.Price = priceaftercomm;
                    d.PriceAfterdiscount = (priceaftercomm - (priceaftercomm * d.Discount / 100));
                }
            }
            return(Data);
        }