예제 #1
0
        public async Task <IActionResult> Detail(int id, int page = 1)
        {
            if (id != 0)
            {
                ViewBag.LikedIt = false;

                var product = await _productrepo.GetById(id);

                int auth = Barayand.Common.Services.TokenService.AuthorizeUser(Request);
                if (auth > 0)
                {
                    ViewBag.LikedIt = await _favoritrepostory.ChekExistsInList(product.P_Id, auth, 1);
                }
                ViewBag.loggedin = auth > 0;

                ViewBag.brand = await _brandrepo.GetById(product.P_BrandId);

                #region Paging
                Paging paging = new Paging();
                paging.TotalCount  = product.Comments.Count();
                paging.PageSize    = 30;
                paging.CurrentPage = page;
                paging.TotalPages  = (int)Math.Ceiling(paging.TotalCount / (double)paging.PageSize);
                ViewBag.paging     = paging;
                #endregion
                var items = product.Comments.Skip((paging.CurrentPage - 1) * paging.PageSize).Take(paging.PageSize).ToList();
                product.Comments = items;
                return(View(product));
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #2
0
        public async Task <IActionResult> LoadImagesByCat(int cat, int page = 1, string title = null)
        {
            try
            {
                var existsGCat = await _gallerycatrepo.GetById(cat);

                if (existsGCat == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                ViewBag.PageSeo = existsGCat.GC_Seo;
                var galleris  = ((List <ImageGalleryModel>)(await _imagerepo.GetAll()).Data).Where(x => x.IG_Status && x.IG_CatId == cat && x.Lang == _lang.GetLang()).OrderBy(x => x.IG_SortField).ToList();
                int pageSize  = 10;
                int totalPage = (int)Math.Ceiling((double)galleris.Count() / pageSize);
                galleris = galleris.Skip((page - 1) * pageSize).Take(pageSize).ToList();

                ViewBag.CurrentPage = page;
                ViewBag.TotalPages  = totalPage;
                ViewBag.Cat         = cat;
                return(View(galleris));
            }
            catch (Exception ex)
            {
                _logger.LogError("ErrorGalleryController", ex);
                return(View(new List <ImageGalleryModel>()));
            }
        }
예제 #3
0
        public async Task <IActionResult> Index()
        {
            var basket = await _basketservice.GetBasketItems(Request);

            ViewBag.LoggedIn = TokenService.AuthorizeUser(Request) > 0;
            ViewBag.User     = await _userrepository.GetById(TokenService.AuthorizeUser(Request));

            return(View(basket));
        }
예제 #4
0
        public async Task <ActionResult> LoadComments()
        {
            try
            {
                var           invoices = ((List <CommentModel>)(await _commentrepo.GetAll()).Data);
                List <object> result   = new List <object>();
                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fa");
                int i = 1;
                foreach (var item in invoices.OrderByDescending(x => x.Created_At))
                {
                    string entityTitle = "";
                    if (item.C_Type == 1)
                    {
                        var prd = await _productrepo.GetById(item.C_EntityId);

                        if (prd != null)
                        {
                            entityTitle = prd.P_Title;
                        }
                    }
                    if (item.C_Type == 5)
                    {
                        var prd = await _noticerepo.GetById(item.C_EntityId);

                        if (prd != null)
                        {
                            entityTitle = prd.N_Title;
                        }
                    }
                    result.Add(new
                    {
                        id     = item.C_Id,
                        etitle = entityTitle,
                        user   = item.C_UserName,
                        email  = item.C_UserEmail,
                        date   = ((DateTime)item.Created_At).ToString("yyyy/MM/dd HH:mm"),
                        body   = item.C_Body,
                        state  = item.C_Status
                    });
                    i++;
                }
                return(new JsonResult(ResponseModel.Success(data: result)));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error in loading Comments", ex);
                return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
            }
        }
        public async Task <IActionResult> Index()
        {
            try
            {
                ViewBag.category = null;
                List <ProductModel> items = new List <ProductModel>();
                string cookie             = "";
                HttpContext.Request.Cookies.TryGetValue("Compaire", out cookie);
                var ProdCatList = (List <ProductCategoryModel>)(await _categories.GetAll()).Data;
                ViewBag.ProductCategory = ProdCatList.Where(x => x.PC_ParentId == 0 && x.PC_Status).ToList();

                if (cookie != null)
                {
                    var decryptCookie      = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie);
                    CompareCookieModel ccm = JsonConvert.DeserializeObject <CompareCookieModel>(decryptCookie);


                    foreach (var item in ccm.Products)
                    {
                        var p = await _productrepo.GetById(item);

                        items.Add(p);
                    }
                }
                if (items.Count() > 0)
                {
                    var getAllProductByCatId = ((List <ProductModel>)(await _productrepo.GetAll()).Data).Where(x => x.P_EndLevelCatId == items.FirstOrDefault().P_EndLevelCatId).ToList();
                    foreach (var item in items)
                    {
                        getAllProductByCatId.Remove(item);
                    }
                    ViewBag.getAllProductByCatId = getAllProductByCatId;
                    #region Brand
                    var BrandGroups = getAllProductByCatId.GroupBy(x => x.P_BrandId)?.Select(x => x.FirstOrDefault().P_BrandId).ToList();
                    ViewBag.Brands = ((List <BrandModel>)(await _brandrepo.GetAll()).Data).Where(x => BrandGroups.Contains(x.B_Id)).ToList();
                    #endregion
                }
                else
                {
                    ViewBag.Brands = ((List <BrandModel>)(await _brandrepo.GetAll()).Data).Where(x => x.B_Status).ToList();
                }
                return(View(items));
            }
            catch (Exception ex)
            {
                return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
            }
        }
        public async Task <IActionResult> Index()
        {
            var basket = await _basketservice.GetBasketItems(Request);

            foreach (var item in basket.CartItems)
            {
                item.Product.PriceModel = await _priceCalculator.CalculateBookPrice(item.Product.P_Id, _lang.GetLang());
            }
            ViewBag.CVRT    = 1000;
            ViewBag.BINPERC = 1;
            var cvrtbase = ((List <OptionsModel>)(await _optionrepository.GetAll()).Data).FirstOrDefault(x => x.O_Key == "CVRTTOMANTOPOINT");
            var bin      = ((List <OptionsModel>)(await _optionrepository.GetAll()).Data).FirstOrDefault(x => x.O_Key == "GIFTBINPERCENTAGE");

            if (bin != null)
            {
                ViewBag.BINPERC = int.Parse(bin.O_Value);
            }
            if (cvrtbase != null)
            {
                ViewBag.CVRT = int.Parse(cvrtbase.O_Value);
            }
            ViewBag.LoggedIn = TokenService.AuthorizeUser(Request) > 0;
            ViewBag.User     = await _userrepository.GetById(TokenService.AuthorizeUser(Request));

            return(View(basket));
        }
예제 #7
0
        public async Task <IActionResult> Detail(int Id = 0, string title = null)
        {
            ViewBag.Category = ((List <NoticesCategoryModel>)(await _categoryrepo.GetAll()).Data).Where(x => x.NC_IsDeleted == false && x.NC_Type == 1).OrderBy(x => x.NC_SortField).ToList();

            var news = await _noticesrepo.GetById(Id);

            ViewBag.catroute = _categoryrepo.GetById(news.N_CId);

            return(View(news));
        }
        public async Task <IActionResult> LoadOrderProducts(string oid)
        {
            try
            {
                var authorize = Barayand.Common.Services.TokenService.AuthorizeUser(Request);
                if (authorize < 1)
                {
                    if (authorize == 0)
                    {
                        Response.Cookies.Delete("GbookUser");
                    }
                    return(new JsonResult(ResponseModel.Error("Your login token has expired.", new { EXPIREDTOKEN = true })));
                }
                var           orders   = ((List <OrderModel>)(await _orderrepository.GetAll()).Data).Where(x => x.O_ReciptId == oid);
                var           rinfo    = ((List <InvoiceModel>)(await _invoicerepository.GetAll()).Data).FirstOrDefault(x => x.I_Id == oid);
                List <object> Products = new List <object>();
                bool          hasHcopy = false;
                int           i        = 1;
                foreach (var item in orders)
                {
                    var prd = await _productrepository.GetById(item.O_ProductId);

                    Products.Add(new {
                        counter  = i,
                        prodname = prd.P_Title,
                        quantity = item.O_Quantity + " عدد",
                        total    = rinfo.I_TotalProductAmount,
                        price    = item.O_Price,
                        version  = (item.O_Version == 1)? "PDF":"HCOPY",
                        downlink = prd.P_DownloadLink
                    });
                    i++;
                    if (item.O_Version == 2)
                    {
                        hasHcopy = true;
                    }
                }
                var reciverinfo = "";
                if (hasHcopy)
                {
                    if (rinfo != null)
                    {
                        reciverinfo = rinfo.I_RecipientInfo;
                    }
                }
                return(new JsonResult(ResponseModel.Success(data: new { hashcopy = hasHcopy, recieptinfo = reciverinfo, products = Products })));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public async Task <ActionResult> LoadAmazingRequests(int type)
        {
            try
            {
                var All = await this._repository.GetAll();

                List <AmazingRequestModel>             data   = ((List <AmazingRequestModel>)(All).Data).Where(x => x.A_Type == type).OrderByDescending(x => x.Created_At).ToList();
                List <OutModels.Models.AmazingRequest> result = _mapper.Map <List <AmazingRequestModel>, List <OutModels.Models.AmazingRequest> >(data);
                foreach (var item in result)
                {
                    var prd = await _productrepository.GetById(item.A_ProductId);

                    if (prd != null)
                    {
                        item.A_ProductTitle = prd.P_Title + "--" + prd.P_Code;
                    }
                    else
                    {
                        item.A_ProductTitle = "----";
                    }
                    var user = await _userrepository.GetById(item.A_UserId);

                    if (user != null)
                    {
                        item.A_UserName = user.U_Name + " " + user.U_Family;
                    }
                    else
                    {
                        item.A_UserName = "******";
                    }
                }
                return(new JsonResult(ResponseModel.Success("AMAZINGREQUEST_LIST_RETURNED", result)));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public async Task <List <PromotionBoxModel> > GetByType(int Type)
        {
            try
            {
                var AllPromotions = ((List <PromotionBoxModel>)(await GetAll()).Data).Where(x => x.B_Type == Type).ToList();
                foreach (var box in AllPromotions)
                {
                    foreach (var item in _context.PromotionBoxProducts.Where(x => x.X_SectionId == box.B_SectionId))
                    {
                        var p = await _productrepo.GetById(item.X_ProdId);

                        if (p != null)
                        {
                            box.Products.Add(p);
                        }
                    }
                }
                return(AllPromotions);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #11
0
 public async Task <ActionResult> GetIndexSections(IndexSectionsModel ism)
 {
     try
     {
         var box = ((List <IndexBoxInfoModel>)(await _indexboxinforepo.GetAll()).Data).Where(x => x.Lang == ism.Lang && x.I_SecId == ism.Section).ToList();
         if (box.Count() < 1)
         {
             return(new JsonResult(ResponseModel.Error(data: new { Products = new List <ProductModel>(), Info = "" })));
         }
         var PIds = ((List <IndexBoxProductRelModel>)(await _indexsectionrepo.GetAll()).Data).Where(x => x.Lang == ism.Lang && x.I_SecId == ism.Section).ToList();
         List <ProductModel> products = new List <ProductModel>();
         foreach (var p in PIds)
         {
             products.Add(await _productrepo.GetById(p.I_Pid));
         }
         return(new JsonResult(ResponseModel.Success(data: new { Products = products, Info = box.FirstOrDefault() })));
     }
     catch (Exception ex)
     {
         return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
     }
 }
예제 #12
0
        public async Task <IActionResult> VideoDetail(int id, string title = null)
        {
            try
            {
                var existsVideo = await _videorepo.GetById(id);

                if (existsVideo == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                ViewBag.PageSeo      = existsVideo.VG_Seo;
                existsVideo.Comments = await _commentRepository.AcceptedComments(existsVideo.VG_Id, 4);

                existsVideo.Rate = (int)await _rateRepository.CalulateRate(existsVideo.VG_Id, 4);

                return(View(existsVideo));
            }
            catch (Exception ex)
            {
                _logger.LogError("ErrorGalleryController", ex);
                return(View(new List <VideoGalleryModel>()));
            }
        }
예제 #13
0
        public async Task <PriceModel> CalculateBookPrice(int pid, string lang)
        {
            try
            {
                ProductModel product = await _productrepo.GetById(pid);

                if (product == null)
                {
                    throw new Exception("محصول مورد نظر یافت نشد");
                }
                PriceModel RESPONSE      = new PriceModel();
                decimal    PDFPRICE      = 0;
                decimal    HARDCOPYPRICE = 0;

                decimal PDFPRICEWODISCOUNT   = 0;
                decimal HCOPYPRICEWODISCOUNT = 0;
                //Calculate pdf price
                DateTime regdate = (DateTime)product.Created_At;
                if (regdate.AddDays(product.P_DiscountPeriodTime) <= DateTime.Now) //if period time started
                {
                    if (product.P_PeriodDiscountPriceType == 1)                    //pay by formula
                    {
                        FormulaModel formul = await _formularepo.GetById(product.P_PriodDiscountFormulaId);

                        if (formul == null)
                        {
                            throw new Exception("فرمول مورد نظر یافت نشد");
                        }
                        DataTable dt             = new DataTable();
                        string    ProductFormula = formul.F_Formula
                                                   .Replace("WEIGHT", product.P_Weight.ToString().Replace("/", "."))
                                                   .Replace("DOLLAR", product.P_ExternalPrice.ToString().Replace("/", "."))
                                                   .Replace("PAGES", product.P_PageCount.ToString().Replace("/", "."));
                        PDFPRICEWODISCOUNT = decimal.Parse(dt.Compute(ProductFormula, "").ToString());
                        PDFPRICE           = product.FinalPrice(price: PDFPRICEWODISCOUNT, onlyPercentag: true);
                    }
                    else//pay by tomans
                    {
                        PDFPRICEWODISCOUNT = product.P_PeriodDiscountPrice;
                        PDFPRICE           = product.FinalPrice(price: PDFPRICEWODISCOUNT, onlyPercentag: true);
                    }

                    if (product.P_PrintAbleVersion)
                    {
                        if (product.P_PrintAbleVerPriceType == 1)
                        {
                            FormulaModel formul = await _formularepo.GetById(product.P_PeriodPrintableFomrulaId);

                            if (formul == null)
                            {
                                throw new Exception("فرمول مورد نظر یافت نشد");
                            }
                            DataTable dt             = new DataTable();
                            string    ProductFormula = formul.F_Formula
                                                       .Replace("WEIGHT", product.P_Weight.ToString().Replace("/", "."))
                                                       .Replace("DOLLAR", product.P_ExternalPrice.ToString().Replace("/", "."))
                                                       .Replace("PAGES", product.P_PageCount.ToString().Replace("/", "."));
                            HCOPYPRICEWODISCOUNT = decimal.Parse(dt.Compute(ProductFormula, "").ToString());
                            HARDCOPYPRICE        = product.FinalPrice(price: HCOPYPRICEWODISCOUNT, onlyPercentag: true);
                        }
                        else
                        {
                            HCOPYPRICEWODISCOUNT = product.P_PeriodPrintablePrice;
                            HARDCOPYPRICE        = product.FinalPrice(price: HCOPYPRICEWODISCOUNT, onlyPercentag: true);
                        }
                    }
                }
                else//period time not started and calculate productprice from main price or main formula id
                {
                    if (product.P_PriceType == 1)//pay by formula
                    {
                        FormulaModel formul = await _formularepo.GetById(product.P_PriceFormulaId);

                        if (formul == null)
                        {
                            throw new Exception("فرمول مورد نظر یافت نشد");
                        }
                        DataTable dt             = new DataTable();
                        string    ProductFormula = formul.F_Formula
                                                   .Replace("WEIGHT", product.P_Weight.ToString().Replace("/", "."))
                                                   .Replace("DOLLAR", product.P_ExternalPrice.ToString().Replace("/", "."))
                                                   .Replace("PAGES", product.P_PageCount.ToString().Replace("/", "."));
                        PDFPRICEWODISCOUNT = decimal.Parse(dt.Compute(ProductFormula, "").ToString());
                        PDFPRICE           = product.FinalPrice(price: PDFPRICEWODISCOUNT, onlyPercentag: true);
                    }
                    else//pay by tomans
                    {
                        PDFPRICEWODISCOUNT = product.P_Price;
                        PDFPRICE           = product.FinalPrice();
                    }
                    if (product.P_PrintAbleVersion)
                    {
                        if (product.P_PrintAbleVerPriceType == 1)
                        {
                            FormulaModel formul = await _formularepo.GetById(product.P_PrintAbleVerFormulaId);

                            if (formul == null)
                            {
                                throw new Exception("فرمول مورد نظر یافت نشد");
                            }
                            DataTable dt             = new DataTable();
                            string    ProductFormula = formul.F_Formula
                                                       .Replace("WEIGHT", product.P_Weight.ToString().Replace("/", "."))
                                                       .Replace("DOLLAR", product.P_ExternalPrice.ToString().Replace("/", "."))
                                                       .Replace("PAGES", product.P_PageCount.ToString().Replace("/", "."));
                            HCOPYPRICEWODISCOUNT = decimal.Parse(dt.Compute(ProductFormula, "").ToString());
                            HARDCOPYPRICE        = product.FinalPrice(price: HCOPYPRICEWODISCOUNT, onlyPercentag: true);
                        }
                        else
                        {
                            HARDCOPYPRICE        = product.P_PrintAbleVerPrice;
                            HCOPYPRICEWODISCOUNT = product.P_PrintAbleVerPrice;
                        }
                    }
                }
                ///
                RESPONSE.PdfPrice = PDFPRICE;
                if (lang == "fa")
                {
                    RESPONSE.PdfPriceFormated             = PDFPRICE.ToString("#,#") + " تومان";
                    RESPONSE.PdfPriceWithOutDiscountStr   = PDFPRICEWODISCOUNT.ToString("#,#") + " تومان";
                    RESPONSE.PdfPriceWithOutDiscount      = PDFPRICEWODISCOUNT;
                    RESPONSE.HcopyPriceWithOutDiscountStr = HCOPYPRICEWODISCOUNT.ToString("#,#") + " تومان";
                    RESPONSE.HcopyPriceWithOutDiscount    = HCOPYPRICEWODISCOUNT;
                    RESPONSE.HcopyPriceFromated           = HARDCOPYPRICE.ToString("#,#") + " تومان";
                }
                else
                {
                    if (product.P_BinPrice == 0)
                    {
                        RESPONSE.PdfPriceFormated = (int)(PDFPRICE / 1000) + " Point";
                    }
                    else
                    {
                        RESPONSE.PdfPriceFormated = (int)product.P_BinPrice + " Point";
                    }
                    RESPONSE.HcopyPriceFromated = (int)(HARDCOPYPRICE / 1000) + " Point";
                }
                RESPONSE.HcopyPrice = HARDCOPYPRICE;

                if (product.P_Discount > 0)
                {
                    RESPONSE.Discount     = product.P_Discount;
                    RESPONSE.Discounted   = true;
                    RESPONSE.DiscountType = product.P_DiscountType;
                }
                return(RESPONSE);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error in calculating product service", ex);
                return(new PriceModel());
            }
        }
예제 #14
0
        public async Task <ActionResult> LoadProductsForBoxs(int page = 1, int count = 5, int pid = 0, string title = null, string code = null)
        {
            try
            {
                List <ProductModel>             data        = (List <ProductModel>)(await this._repository.GetAll()).Data;
                List <ProductCombineModel>      AllCombines = ((List <ProductCombineModel>)(await this._combinerepository.GetAll()).Data).Where(x => !x.X_IsDeleted).ToList();
                List <OutModels.Models.Product> result      = new List <OutModels.Models.Product>();
                if (pid != 0)
                {
                    result = _mapper.Map <List <ProductModel>, List <OutModels.Models.Product> >(data.Where(x => x.P_Id != pid).ToList());
                }
                else
                {
                    result = _mapper.Map <List <ProductModel>, List <OutModels.Models.Product> >(data.ToList());
                }

                if (title != null)
                {
                    result = result.Where(x => x.P_Title.Contains(title, StringComparison.InvariantCultureIgnoreCase) || x.P_Code.Contains(title, StringComparison.InvariantCultureIgnoreCase)).ToList();
                }
                if (code != null)
                {
                    result = result.Where(x => x.P_Code.Contains(code, StringComparison.InvariantCultureIgnoreCase)).ToList();
                }

                List <object> Prods = new List <object>();
                foreach (var item in result)
                {
                    var ProdCombines = AllCombines.Where(x => x.X_ProductId == item.P_Id && x.X_Status && !x.X_IsDeleted).ToList();
                    if (ProdCombines.Count > 0)
                    {
                        int i = 1;
                        foreach (var combine in ProdCombines)
                        {
                            var w = await _warrantyrepo.GetById(combine.X_WarrantyId);

                            var c = await _colorrepo.GetById(combine.X_ColorId);

                            if (w != null && c != null)
                            {
                                Prods.Add(new
                                {
                                    counter      = i,
                                    id           = item.P_Id,
                                    code         = item.P_Code,
                                    title        = item.P_Title,
                                    warranty     = w.W_Title,
                                    wid          = w.W_Id,
                                    cid          = c.C_Id,
                                    color        = c.C_Title,
                                    price        = combine.X_Price.ToString("#,#"),
                                    discount     = combine.X_Discount,
                                    sdate        = new string[] { },
                                    stime        = "",
                                    etime        = "",
                                    status       = true,
                                    showinindex  = true,
                                    discounttype = true
                                });
                                i++;
                            }
                        }
                    }
                }
                int totalPages = (int)Math.Ceiling((double)Prods.Count() / count);
                Prods = Prods.Skip(count * (page - 1)).Take(count).ToList();
                return(new JsonResult(ResponseModel.Success("PRODUCTS_LIST_RETURNED", new { Products = Prods, TotalPages = totalPages, CurrentPage = page })));
            }
            catch (Exception ex)
            {
                return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
            }
        }
        public async Task <ProductCombinePriceModel> CalculateProductCombinePrice(int cid, int EndLevelCatId = 0)
        {
            try
            {
                ProductCombinePriceModel PriceModel = new ProductCombinePriceModel();
                var existsCombine = await _combinerepo.GetById(cid);

                if (existsCombine != null)
                {
                    List <FestivalOfferModel> AllFestivalRepo = ((List <FestivalOfferModel>)(await _festrepo.GetAll()).Data);
                    var existsInBox = await _boxProdRepository.CheckProductCombineExistsInBox(existsCombine.X_ProductId, existsCombine.X_WarrantyId, existsCombine.X_ColorId);

                    if (existsInBox != null)
                    {
                        var defaultCombine = existsCombine;

                        PriceModel.Price = defaultCombine.X_Price;
                        if (existsInBox.X_SectionId == 34 && (DateTime.Now >= existsInBox.X_StartDate && DateTime.Now <= existsInBox.X_EndDate)) //is special sale and timer started
                        {
                            if (existsInBox.X_DiscountedPrice > 0)                                                                               //has discount
                            {
                                PriceModel.HasDiscount = true;
                                if (!existsInBox.X_DiscountType) // please calculate price by percentage
                                {
                                    PriceModel.Discount        = existsInBox.X_DiscountedPrice;
                                    PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * existsInBox.X_DiscountedPrice) / 100));
                                }
                                else//calculate percentage by price
                                {
                                    PriceModel.Discount        = ((existsInBox.X_DiscountedPrice * 100) / defaultCombine.X_Price);
                                    PriceModel.DiscountedPrice = existsInBox.X_DiscountedPrice;
                                }
                            }
                            PriceModel.Timer = existsInBox.X_EndDate.ToString("yyyy-MM-dd HH:mm:ss");
                        }

                        if (existsInBox.X_SectionId != 34)
                        {
                            if (existsInBox.X_DiscountedPrice > 0)//has discount
                            {
                                PriceModel.HasDiscount = true;
                                if (!existsInBox.X_DiscountType) // please calculate price by percentage
                                {
                                    PriceModel.Discount        = existsInBox.X_DiscountedPrice;
                                    PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * existsInBox.X_DiscountedPrice) / 100));
                                }
                                else//calculate percentage by price
                                {
                                    PriceModel.Discount        = ((existsInBox.X_DiscountedPrice * 100) / defaultCombine.X_Price);
                                    PriceModel.DiscountedPrice = existsInBox.X_DiscountedPrice;
                                }
                            }
                        }
                    }
                    else if (AllFestivalRepo.Count(x => x.F_Type == 1 && x.F_Status) > 0)
                    {
                        var fest           = AllFestivalRepo.FirstOrDefault(x => x.F_Type == 1);
                        var defaultCombine = existsCombine;
                        var cmb            = await SetDiscountByCombine(defaultCombine, fest.F_Discount);

                        PriceModel = cmb.PriceModel;
                    }
                    else if (EndLevelCatId != 0 && AllFestivalRepo.Count(x => x.F_Type == 2 && x.F_Status && x.F_EndLevelCategoryId == EndLevelCatId) > 0)
                    {
                        var fest = AllFestivalRepo.FirstOrDefault(x => x.F_Type == 2 && x.F_Status && x.F_EndLevelCategoryId == EndLevelCatId);
                        var cmb  = await SetDiscountByCombine(existsCombine, fest.F_Discount);

                        PriceModel = cmb.PriceModel;
                    }
                }
                return(PriceModel);
            }
            catch (Exception ex)
            {
                return(new ProductCombinePriceModel());
            }
        }
예제 #16
0
        public async Task <IActionResult> Index(
            string TitleSerch,
            int?order        = null,
            bool isAvilable  = false,
            bool fast        = false,
            bool isajax      = false,
            int[] Brand      = null,
            int[] attribute  = null,
            int cat1         = 0,
            int cat2         = 0,
            int page         = 1,
            decimal minPrice = 0,
            decimal maxprice = 0
            )
        {
            try
            {
                var refUrl      = Request.Headers["Referer"].ToString();
                var ProdCatList = (List <ProductCategoryModel>)(await _categories.GetAll()).Data;
                if (refUrl.Contains("offer") || refUrl.Contains("Offer"))
                {
                    ViewBag.FilterOffered = true;
                }
                else
                {
                    ViewBag.FilterOffered = false;
                }
                ViewBag.ProductCategory = ProdCatList.Where(x => x.PC_ParentId == cat1 && x.PC_Status && !x.PC_IsDeleted).ToList();
                var Catlvl1 = await _categories.GetById(cat1);

                if (Catlvl1 != null)
                {
                    ViewBag.CatTitle    = Catlvl1.PC_Title;
                    ViewBag.description = Catlvl1.PC_Description;
                    ViewBag.CatSeo      = Catlvl1.PC_Seo;
                    ViewBag.CatL1       = Catlvl1;
                }
                else
                {
                    ViewBag.CatL1 = null;
                }
                if (cat2 > 0)
                {
                    var Catlvl2 = await _categories.GetById(cat2);

                    if (Catlvl2 != null)
                    {
                        ViewBag.description = Catlvl2.PC_Description;
                        ViewBag.CatSeo      = Catlvl2.PC_Seo;
                        ViewBag.CatL2       = Catlvl2;
                    }
                    else
                    {
                        ViewBag.CatL2 = null;
                    }
                }
                else
                {
                    ViewBag.CatL2 = null;
                }
                var seo = Barayand.Common.Services.UtilesService.ParseSeoData(Catlvl1.PC_Seo);
                ViewBag.CatId  = cat1;
                ViewBag.CatId2 = cat2;

                ViewBag.pagetype = 1;
                ViewBag.CatUrl1  = seo.url.ToString();
                var AllProduct = ((List <ProductModel>)(await _productrepo.GetAll()).Data).Where(x => x.P_Status && x.P_MainCatId == cat1).OrderBy(x => x.P_Sort).OrderBy(x => x.P_LabelIds.Count() > 0) /*.OrderBy(x=>x.P_Labels.FirstOrDefault(l=>l.L_Title.Equals("جدید")))*/.ToList();
                if (cat2 > 0)
                {
                    AllProduct = AllProduct.Where(x => x.P_EndLevelCatId == cat2).ToList();
                }
                ViewBag.Minprice = 0;
                ViewBag.MaxPrice = 10;
                #region GetPrice
                if (AllProduct.Where(x => x.IsAvailable).Count() > 0)
                {
                    ViewBag.Minprice = AllProduct.Where(x => x.DefaultProductCombine != null).Min(x => x.DefaultProductCombine.PriceModel.Price);
                    ViewBag.MaxPrice = AllProduct.Where(x => x.DefaultProductCombine != null).Max(x => x.DefaultProductCombine.PriceModel.Price);
                }
                #endregion
                #region Attrbute
                if (!isajax)
                {
                    List <AttributeAnswerList>  Attributes = new List <AttributeAnswerList>();
                    List <CatAttrRelationModel> catAttrs   = ((List <CatAttrRelationModel>)(await _catattrrepo.GetAll()).Data).Where(x => x.X_IsDeleted != true).ToList();
                    foreach (var catttr in catAttrs)
                    {
                        if (catttr.X_CatId == cat1 || catttr.X_CatId == cat2)
                        {
                            var attr = await _attrrepo.GetById(catttr.X_AttrId);

                            if (attr != null && attr.A_Type == 1 && attr.A_UseInSearch && attr.A_Status && attr.A_IsDeleted == false)
                            {
                                List <AttrAnswerModel> answers = ((List <AttrAnswerModel>)(await _attransrepo.GetAll()).Data).Where(x => x.X_CatAttrId == catttr.X_Id && !x.X_IsDeleted && x.X_Status).ToList();
                                Attributes.Add(new AttributeAnswerList()
                                {
                                    Attribute = attr,
                                    Answers   = answers
                                });
                            }
                        }
                    }
                    ViewBag.Attributes = Attributes;
                }
                #endregion
                #region Brand
                var BrandGroups = AllProduct.GroupBy(x => x.P_BrandId)?.Select(x => x.FirstOrDefault().P_BrandId).ToList();
                ViewBag.Brands = ((List <BrandModel>)(await _brandrepo.GetAll()).Data).Where(x => BrandGroups.Contains(x.B_Id)).ToList();
                #endregion
                #region Filter
                if (cat2 != 0)
                {
                    AllProduct = AllProduct.Where(x => x.P_EndLevelCatId == cat2).ToList();
                }
                if (!string.IsNullOrEmpty(order.ToString()))
                {
                    switch (order)
                    {
                    case 1:     //See
                        AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList();
                        break;

                    case 2:    //sell
                        AllProduct = AllProduct.OrderByDescending(x => x.P_SaleCount).ToList();
                        break;

                    case 3:    //fav
                        AllProduct = AllProduct.OrderByDescending(x => x.ManualRate).ToList();

                        break;

                    case 4:    //new
                        AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList();
                        break;

                    case 5:    //cheap
                        AllProduct = AllProduct.Where(x => x.DefaultProductCombine != null && x.DefaultProductCombine.PriceModel != null).OrderBy(x => (x.DefaultProductCombine.PriceModel.Price)).ToList();
                        break;

                    case 6:    //expenc
                        AllProduct = AllProduct.Where(x => x.DefaultProductCombine != null && x.DefaultProductCombine.PriceModel != null).OrderByDescending(x => x.DefaultProductCombine.PriceModel.Price).ToList();

                        break;

                    case 7:    //fast
                        AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList();
                        break;

                    case 8:    //bestoffer
                        AllProduct = AllProduct.Where(x => x.P_BestOffer).ToList();
                        break;

                    default:
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(TitleSerch))
                {
                    AllProduct = AllProduct.Where(x => x.P_Title.Contains(TitleSerch, StringComparison.InvariantCultureIgnoreCase)).ToList();
                }
                if (Brand != null && Brand.Count() > 0)
                {
                    AllProduct = AllProduct.Where(x => Brand.Contains(x.P_BrandId)).ToList();
                }
                if (attribute != null && attribute.Count() > 0)
                {
                    List <int> AllFilteredProdsByAnsId = new List <int>();
                    foreach (int aid in attribute)
                    {
                        var r = await _prodansRepo.GetProductsByAnswer(aid);

                        AllFilteredProdsByAnsId.AddRange(r);
                    }
                    AllProduct = AllProduct.Where(x => AllFilteredProdsByAnsId.Contains(x.P_Id)).ToList();
                }
                if (fast)
                {
                    AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList();
                }
                if (isAvilable)
                {
                    AllProduct = AllProduct.Where(x => x.IsAvailable).ToList();
                }
                if (minPrice > 0 && maxprice > 0)
                {
                    AllProduct = AllProduct.Where(x => x.DefaultProductCombine.PriceModel.Price >= minPrice && x.DefaultProductCombine.PriceModel.Price <= maxprice).ToList();
                }
                #endregion
                #region Paging
                Paging paging = new Paging();
                paging.TotalCount = AllProduct.Count();
                paging.PageSize   = 30;

                if ((int)Math.Ceiling(paging.TotalCount / (double)paging.PageSize) < page)
                {
                    page = 1;
                }
                paging.CurrentPage = page;
                paging.TotalPages  = (int)Math.Ceiling(paging.TotalCount / (double)paging.PageSize);
                ViewBag.paging     = paging;
                #endregion
                if (ViewBag.Minprice == ViewBag.MaxPrice)
                {
                    ViewBag.MaxPrice = ViewBag.MaxPrice + 100;
                }
                var items = AllProduct.Skip((paging.CurrentPage - 1) * paging.PageSize).Take(paging.PageSize).ToList();
                if (isajax)
                {
                    return(View("_ProductList", items));
                }
                return(View(items));
            }
            catch (Exception ex)
            {
                _logger.LogError("", ex);
                return(Content(ex.Message));
            }
        }
예제 #17
0
        public async Task <IActionResult> Country(
            int id,
            string TitleSerch,
            bool isAjax,
            int?order        = null,
            decimal minPrice = 0,
            bool isAvilable  = false,
            bool fast        = false,
            decimal maxprice = 0,
            int page         = 1,
            int?catid        = null
            )
        {
            try
            {
                int?catlvlcheck = null;
                var AllProduct  = ((List <ProductModel>)(await _productrepo.GetAll()).Data).Where(x => x.P_Status && x.P_MCuntryId == id).ToList();

                ViewBag.country = await _Cuntry.GetById(id);

                ViewBag.catid    = catid;
                ViewBag.pagetype = 3;
                ViewBag.Minprice = 0;
                ViewBag.MaxPrice = 0;
                ViewBag.openattr = null;
                if (catid != null)
                {
                    var catbrand = await _categories.GetById(catid);

                    catlvlcheck = (catbrand.PC_ParentId == 0) ? 1 : 2;

                    if (catbrand.PC_ParentId == 0)
                    {
                        ViewBag.openattr = catid;
                    }
                    else
                    {
                        ViewBag.openattr = catbrand.PC_ParentId;
                    }
                }
                #region Category
                var Catlvl2 = AllProduct.GroupBy(x => x.P_EndLevelCatId)?.Select(x => x.FirstOrDefault().P_EndLevelCatId).ToList();
                var Catlvl1 = AllProduct.GroupBy(x => x.P_MainCatId)?.Select(x => x.FirstOrDefault().P_MainCatId).ToList();
                ViewBag.Catlvl2 = ((List <ProductCategoryModel>)(await _categories.GetAll()).Data).Where(x => Catlvl2.Contains(x.PC_Id)).ToList();
                ViewBag.Catlvl1 = ((List <ProductCategoryModel>)(await _categories.GetAll()).Data).Where(x => Catlvl1.Contains(x.PC_Id)).ToList();
                #endregion
                #region GetPrice
                if (AllProduct.Where(x => x.IsAvailable).Count() > 0)
                {
                    ViewBag.Minprice = AllProduct.Where(x => x.DefaultProductCombine != null).Min(x => x.DefaultProductCombine.PriceModel.Price);
                    ViewBag.MaxPrice = AllProduct.Where(x => x.DefaultProductCombine != null).Max(x => x.DefaultProductCombine.PriceModel.Price);
                }
                #endregion
                #region Filter
                if (!string.IsNullOrEmpty(TitleSerch))
                {
                    AllProduct = AllProduct.Where(x => x.P_Title.Contains(TitleSerch, StringComparison.InvariantCultureIgnoreCase)).ToList();
                }
                if (!string.IsNullOrEmpty(order.ToString()))
                {
                    switch (order)
                    {
                    case 1:     //See
                        AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList();
                        break;

                    case 2:    //sell
                        AllProduct = AllProduct.OrderByDescending(x => x.P_SaleCount).ToList();
                        break;

                    case 3:    //fav
                        AllProduct = AllProduct.OrderByDescending(x => x.ManualRate).ToList();

                        break;

                    case 4:    //new
                        AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList();
                        break;

                    case 5:    //cheap
                        AllProduct = AllProduct.Where(x => x.DefaultProductCombine != null && x.DefaultProductCombine.PriceModel != null).OrderBy(x => (x.DefaultProductCombine.PriceModel.Price)).ToList();
                        break;

                    case 6:    //expenc
                        AllProduct = AllProduct.Where(x => x.DefaultProductCombine != null && x.DefaultProductCombine.PriceModel != null).OrderByDescending(x => x.DefaultProductCombine.PriceModel.Price).ToList();

                        break;

                    case 7:    //fast
                        AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList();
                        break;

                    case 8:    //bestoffer
                        AllProduct = AllProduct.Where(x => x.P_BestOffer).ToList();
                        break;

                    default:
                        break;
                    }
                }
                if (fast)
                {
                    AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList();
                }
                if (isAvilable)
                {
                    AllProduct = AllProduct.Where(x => x.IsAvailable).ToList();
                }
                if (minPrice > 0 && maxprice > 0)
                {
                    AllProduct = AllProduct.Where(x => x.DefaultProductCombine.PriceModel.Price >= minPrice && x.DefaultProductCombine.PriceModel.Price <= maxprice).ToList();
                }
                if (catid != null)
                {
                    AllProduct = AllProduct.Where(x => x.P_EndLevelCatId == catid || x.P_MainCatId == catid).ToList();
                }
                #endregion
                #region Paging
                Paging paging = new Paging();
                paging.TotalCount  = AllProduct.Count();
                paging.PageSize    = 30;
                paging.CurrentPage = page;
                paging.TotalPages  = (int)Math.Ceiling(paging.TotalCount / (double)paging.PageSize);
                ViewBag.paging     = paging;
                #endregion

                var items = AllProduct.Skip((paging.CurrentPage - 1) * paging.PageSize).Take(paging.PageSize).ToList();
                if (isAjax)
                {
                    return(View("_ProductList", items));
                }
                return(View(items));
            }
            catch (Exception ex)
            {
                _logger.LogError("", ex);
                return(RedirectToAction("Index", "Home"));
            }
        }
예제 #18
0
        public async Task <ActionResult> LoadInvoices()
        {
            try
            {
                var           invoices = ((List <InvoiceModel>)(await _invoicerepo.GetAll()).Data);
                List <object> result   = new List <object>();
                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fa");
                int i = 1;
                foreach (var item in invoices.OrderByDescending(x => x.Created_At))
                {
                    var           orders        = ((List <OrderModel>)(await _orderrepo.GetAll()).Data).Where(x => x.O_ReciptId == item.I_Id).ToList();
                    List <object> InvoiceOrders = new List <object>();
                    int           j             = 1;
                    foreach (var o in orders)
                    {
                        var product = await _productrepo.GetById(o.O_ProductId);

                        if (product != null)
                        {
                            InvoiceOrders.Add(new {
                                Counter         = j,
                                Name            = product.P_Title,
                                Image           = product.P_Image,
                                Price           = o.O_Price,
                                PriceWODiscount = o.O_Discount,
                                Quantity        = o.O_Quantity,
                                Version         = o.O_Version,
                                Lang            = o.Lang
                            });
                            j++;
                        }
                    }
                    var user = await _userrepo.GetById(item.I_UserId);

                    var coupon = await _copponrepo.GetById(item.I_CopponId);

                    result.Add(new {
                        Counter     = i,
                        Id          = item.ID,
                        Code        = item.I_Id,
                        User        = (user != null) ? user.U_Name + " " + user.U_Family : "",
                        Sum         = item.I_TotalAmount,
                        SumProducts = item.I_TotalProductAmount,
                        CouponCode  = (coupon != null) ? coupon.CP_Code : "",
                        CouponPerc  = item.I_CopponDiscount,
                        PaymentType = item.I_PaymentType,
                        BankName    = "Test Payment",
                        CardNumber  = "Test Payment",
                        PaymentDate = ((DateTime)item.Created_At).ToString("yyyy/MM/dd HH:mm:ss"),
                        Status      = item.I_Status,
                        Reciption   = (item.I_RecipientInfo != null) ? JsonConvert.DeserializeObject <ReciptientInfoModel>(item.I_RecipientInfo) : null,
                        Products    = InvoiceOrders
                    });
                    i++;
                }
                return(new JsonResult(ResponseModel.Success(data: result)));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error in loading invoices", ex);
                return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
            }
        }
예제 #19
0
        public async Task <BasketViewModel> GetBasketItems(HttpRequest httpRequest)
        {
            try
            {
                BasketViewModel basketView = new BasketViewModel();
                string          cookie;
                if (httpRequest.Cookies.TryGetValue("Cart", out cookie))
                {
                    if (cookie != null)
                    {
                        FullPropertyBasketModel BasketModel = new FullPropertyBasketModel();
                        var basketInfo = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie);
                        BasketModel = JsonConvert.DeserializeObject <FullPropertyBasketModel>(basketInfo);
                        decimal SumWithDiscount    = 0;
                        decimal SumWithOutDiscount = 0;
                        if (BasketModel.CartItems.Count() > 0)
                        {
                            List <ProductList> productLists = new List <ProductList>();
                            foreach (var item in BasketModel.CartItems)
                            {
                                ProductList productList = new ProductList();
                                if (item.ProductType == 1)//item is product combine
                                {
                                    var productcomine = await _productcombinerepo.GetById(item.ProductCombineId);

                                    if (productcomine != null)
                                    {
                                        ProductModel product = await _productrepo.GetById(productcomine.X_ProductId);

                                        if (product != null)
                                        {
                                            var priceModel = await _priceCalculator.CalculateProductCombinePrice(productcomine.X_Id, product.P_EndLevelCatId);

                                            productList.ProductTitle     = product.P_Title;
                                            productList.ProductImage     = product.P_Image;
                                            productList.ProductCombineId = productcomine.X_Id;
                                            productList.Quantity         = item.Quantity;
                                            productList.Price            = priceModel.Price;
                                            productList.DiscountedPrice  = priceModel.DiscountedPrice;
                                            if (priceModel.HasDiscount)
                                            {
                                                productList.Total = (productList.DiscountedPrice * item.Quantity);
                                                SumWithDiscount  += productList.Total;
                                            }
                                            else
                                            {
                                                productList.Total = (productList.Price * item.Quantity);
                                                if (!await _priceCalculator.checkProductCombineExistsDiscount(item.ProductCombineId, product.P_EndLevelCatId))
                                                {
                                                    SumWithOutDiscount += productList.Total;
                                                }
                                            }
                                            productList.IsAvailable   = (productcomine.X_AvailableCount >= item.Quantity);
                                            productList.ColorTitle    = productcomine.ColorDetail.C_Title;
                                            productList.WarrantyTitle = productcomine.WarrantyModel.W_Title;
                                            productList.GiftProduct   = product.Gift;
                                            productLists.Add(productList);
                                        }
                                    }
                                }
                                else//item is product manual
                                {
                                    var manual = await _productmanualrepo.GetById(item.ProductCombineId);

                                    if (manual != null)
                                    {
                                        var product = await _productrepo.GetById(manual.M_ProductId);

                                        if (product != null)
                                        {
                                            productList.ProductTitle     = manual.M_Title + "-" + product.P_Title;
                                            productList.ProductImage     = product.P_Image;
                                            productList.ProductCombineId = 0;
                                            productList.Quantity         = item.Quantity;
                                            productList.Price            = manual.M_Price;
                                            productList.DiscountedPrice  = 0;
                                            productList.Total            = (productList.Price * item.Quantity);
                                            productList.ColorTitle       = "---";
                                            productList.WarrantyTitle    = "---";
                                            productList.GiftProduct      = null;
                                            productLists.Add(productList);
                                        }
                                    }
                                }
                            }
                            basketView.Products.AddRange(productLists);
                            basketView.ReciptientInfo = BasketModel.RecipientInfo;
                            if (BasketModel.Coppon.Count() > 0)
                            {
                                var c = BasketModel.Coppon.FirstOrDefault();
                                if (SumWithOutDiscount > 0)
                                {
                                    var clc = (SumWithOutDiscount - c.CP_Discount);
                                    clc = clc < 0 ? 0 : clc;
                                    BasketModel.Total = clc + SumWithDiscount;
                                }
                                else
                                {
                                    BasketModel.Total = SumWithDiscount;
                                }
                                var coupunAmount = c.CP_Discount;
                                basketView.CouponInfo = new Coupon()
                                {
                                    CouponAmount = coupunAmount, CouponDiscount = c.CP_Discount, CouponId = c.CP_Code
                                };
                            }
                            else
                            {
                                BasketModel.Total = SumWithDiscount + SumWithOutDiscount;
                            }
                            basketView.Total = BasketModel.Total;
                        }
                    }
                }

                return(basketView);
            }
            catch (Exception ex)
            {
                return(new BasketViewModel());
            }
        }