Example #1
0
        public async Task <IActionResult> Cart()
        {
            var model = new MultiModels();

            //Query String
            //model.UserList = (from u in _userManager.Users orderby u.Id descending select u).Take(10).ToList();
            //model.LastNews = (from n in _context.news orderby n.NewsId descending select n).Take(5).ToList();

            var userId = _userManager.GetUserId(User);

            model.Address     = _context.Address.Where(a => a.UserId == userId).SingleOrDefault();
            model.CurrentUser = _context.Users.Where(a => a.Id == userId).SingleOrDefault();

            if (Request.Cookies["ATB"] != null)
            {
                string   cookieContent = Request.Cookies["ATB"].ToString();
                string[] requestedBook = cookieContent.Split(',');
                requestedBook         = requestedBook.Where(r => r != null).ToArray();
                model.SearchedProduct = (from b in _context.products
                                         where requestedBook.Contains(b.ProductId.ToString())
                                         select new Product
                {
                    ProductId = b.ProductId,
                    ProductName = b.ProductName,
                    ProductPrice = b.ProductPrice,
                    ProductDiscount = b.ProductDiscount
                }).ToList();
            }

            ViewBag.imagepath = "/upload/normalimage/";
            var queryFullname = (from u in _context.Users where u.Id == _userManager.GetUserId(HttpContext.User) select u).SingleOrDefault();

            return(View(model));
        }
Example #2
0
        [AllowAnonymous] // برای دسترسی همه
        public IActionResult BookDetails(int Id)
        {
            if (Id == 0)
            {
                return(RedirectToAction("NotFounds"));
            }
            // get name of user
            if (_signInManager.IsSignedIn(User))
            {
                // get name of user
                string UserId = _ius.GetId();
                ViewBag.fullname = _ius.GetById(UserId).FirstName + " " + _ius.GetById(UserId).LastName;
                // update wallet
                ViewBag.Wallet = _ius.GetById(UserId).Wallet;
            }


            ViewBag.imageThumbnail = "/upload/thumbnailimage/";
            ViewBag.normalimage    = "/upload/normalimage/";
            ViewBag.normalnews     = "/upload/normalnews/";
            ViewBag.thumbnailnews  = "/upload/thumbnailnews/";

            var model = new MultiModels();

            model.BookDetail   = _ibs.BookDetail(Id);
            model.moreViewBook = _ibs.MoreViewBook();

            _ibs.ViewPlus(Id);
            return(View(model));
        }
Example #3
0
        public async Task <IActionResult> Payment(MultiModels t)
        {
            //Order(userId, tp);

            if (t.Transaction.Amount == 0)
            {
                ModelState.AddModelError("AmountError", "مبلغ خالی است");
            }

            //From Zarinpal
            var payment = await new ZarinpalSandbox.Payment(t.Transaction.Amount).PaymentRequest("توضیحات",
                                                                                                 Url.Action(nameof(PaymentVerify), "Product", new
            {
                amount = t.Transaction.Amount,
                Email  = t.Transaction.Email,
                Desc   = t.Transaction.Description
            }
                                                                                                            , Request.Scheme),
                                                                                                 t.Transaction.Email, t.CurrentUser.PhoneNumber);

            //درصورت موفقیت آمیز بودن درخواست کاربر را به صفحه درخواست هدایت کن
            //در غیراینصورت باید خطا نمایش داده شود
            return(payment.Status == 100 ? (IActionResult)Redirect(payment.Link) :
                   BadRequest($"خطا در پرداخت، کد خطا :  { payment.Status}"));
        }
        public IActionResult Index()
        {
            MultiModels Mulmodel = new MultiModels();

            Mulmodel.LstEmployee = Empcontext.Employees.ToList();
            Mulmodel.Emp         = new Employee();

            return(View("Index2", Mulmodel));
        }
        public IActionResult Index()
        {
            MultiModels MulMod = new MultiModels();
            Employee    empt   = new Employee();

            empt.EmployeeId    = 0;
            MulMod.LstEmployee = EmpDal.GetAllEmployee().ToList();
            MulMod.Emp         = empt;
            return(View("Index", MulMod));
        }
Example #6
0
        public IActionResult BookRequest(string UserId)
        {
            if (_signInManager.IsSignedIn(User))
            {
                // get name of user
                string UserId_ = _ius.GetId();
                ViewBag.fullname = _ius.GetById(UserId_).FirstName + " " + _ius.GetById(UserId_).LastName;
                // update wallet
                ViewBag.Wallet = _ius.GetById(UserId_).Wallet;
            }
            // -1. check total price is lower wallet of User
            // 0. check request befor (prevent repeat)
            // 1. save in data base
            // 2. clear cookies
            //string UserID = _userManager.GetUserId(HttpContext.User);
            string cookieContent = Request.Cookies["_gharz"].ToString();

            string[] listShop = cookieContent.Split(",").Where(r => r != "").ToArray();
            var      model    = new MultiModels();

            // step: -1
            if (Request.Cookies["_gharz"] != null)
            {
                // query to sql
                model.listShop = _ibs.GetByIdRange(listShop);
            }
            long totalPrice = model.listShop.Sum(b => b.Price);

            string userid_     = _ius.GetId();
            long   wallet_user = _ius.GetById(userid_).Wallet;

            if (totalPrice > wallet_user)
            {
                return(Json(new { status = "fail", message = "موجودی شما کافی نیست" }));
            }

            // step: 0
            if (Request.Cookies["_gharz"] != null)
            {
                var query = _ibs.BorrowCheck(_ius.GetId(), listShop);
                if (query.Count() > 0)
                {
                    return(Json(new { status = "exist", message = "لیست شامل کتابی است که قبلا درخواست داده اید" }));
                }
            }

            // step: 1
            // استفاده از ترنزکشن
            _ibs.saveBorrow(listShop, userid_, dtPersian.shamsiDate(), totalPrice);

            // step: 2
            Response.Cookies.Delete("_gharz");
            return(Json(new { status = "success", message = "ثبت شد و منتظر تایید نهایی باید" }));
            //}
        }
        public async Task <IActionResult> Update(int?id)
        {
            if (id != null)
            {
                Employee emp = await Empcontext.Employees.FindAsync(id);

                MultiModels Mulmodel = new MultiModels();
                Mulmodel.LstEmployee = Empcontext.Employees.ToList();
                Mulmodel.Emp         = emp;
                return(View("Index2", Mulmodel));
            }
            return(RedirectToAction("Index"));
        }
Example #8
0
        public IActionResult DeleteRequestedProduct(int id)
        {
            string cookieContent = Request.Cookies["ATB"].ToString();

            string[] bookIdRequested = cookieContent.Split(',');
            bookIdRequested = bookIdRequested.Where(b => b != "").ToArray();
            //ezafe kardan yek araye be list
            List <string> idList = new List <string>(bookIdRequested);

            idList.Remove(id.ToString());

            cookieContent = "";
            for (int i = 0; i < idList.Count(); i++)
            {
                cookieContent += "," + idList[i] + ",";
            }

            Response.Cookies.Append("ATB", cookieContent, new CookieOptions()
            {
                Expires = DateTime.Now.AddMinutes(30)
            });

            var model = new MultiModels();

            //Query String
            //model.UserList = (from u in _userManager.Users orderby u.Id descending select u).Take(10).ToList();
            //model.LastNews = (from n in _context.news orderby n.NewsId descending select n).Take(5).ToList();

            if (Request.Cookies["ATB"] != null)
            {
                string[] requestedBook = cookieContent.Split(',');
                requestedBook         = requestedBook.Where(r => r != null).ToArray();
                model.SearchedProduct = (from b in _context.products
                                         where requestedBook.Contains(b.ProductId.ToString())
                                         select new Product
                {
                    ProductId = b.ProductId,
                    ProductName = b.ProductName,
                    ProductPrice = b.ProductPrice,
                    ProductDiscount = b.ProductDiscount
                }).ToList();
            }

            ViewBag.imagepath = "/upload/normalimage/";
            return(View("Cart", model));
        }
        public IActionResult Update(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            MultiModels MulMod = new MultiModels();

            MulMod.Emp = EmpDal.GetEmployeeById(id);

            if (MulMod.Emp == null)
            {
                return(NotFound());
            }
            MulMod.LstEmployee = EmpDal.GetAllEmployee().ToList();
            return(View("Index", MulMod));
        }
Example #10
0
        public IActionResult listShopDelete(int id)
        {
            if (_signInManager.IsSignedIn(User))
            {
                // get name of user
                string UserId = _ius.GetId();
                ViewBag.fullname = _ius.GetById(UserId).FirstName + " " + _ius.GetById(UserId).LastName;
                // update wallet
                ViewBag.Wallet = _ius.GetById(UserId).Wallet;
            }

            string cookieContent = Request.Cookies["_gharz"].ToString();

            string[] listShop = cookieContent.Split(",").Where(r => r != "").ToArray();

            // generic list
            List <string> idlist = new List <string>(listShop);

            idlist.Remove(id.ToString());

            cookieContent = "";
            foreach (var item in idlist)
            {
                cookieContent += "," + item + ",";
            }
            Response.Cookies.Append("_gharz", cookieContent, new Microsoft.AspNetCore.Http.CookieOptions()
            {
                Expires = DateTime.Now.AddMinutes(30)
            });
            //--------------
            var model = new MultiModels();

            if (Request.Cookies["_gharz"] != null)
            {
                string[] requestBook = cookieContent.Split(",").Where(r => r != "").ToArray();
                // query to sql
                model.listShop = _ibs.GetByIdRange(requestBook);
            }
            return(View("ListShop", model));
        }
Example #11
0
        public IActionResult ListShop()
        {
            if (_signInManager.IsSignedIn(User))
            {
                // get name of user
                string UserId = _ius.GetId();
                ViewBag.fullname = _ius.GetById(UserId).FirstName + " " + _ius.GetById(UserId).LastName;
                // update wallet
                ViewBag.Wallet = _ius.GetById(UserId).Wallet;
            }

            var model = new MultiModels();

            if (Request.Cookies["_gharz"] != null)
            {
                string   cookieContent = Request.Cookies["_gharz"].ToString();
                string[] requestBook   = cookieContent.Split(",").Where(r => r != "").ToArray();
                // query to sql
                model.listShop = _ibs.GetByIdRange(requestBook);
            }
            return(View(model));
        }
Example #12
0
        public async Task <IActionResult> Address(MultiModels model, int AddressId)
        {
            if (ModelState.IsValid)
            {
                /***********************/
                if (AddressId == 0)
                {
                    //Insert
                    using (var db = _iServiceProvider.GetRequiredService <ApplicationDbContext>())
                    {
                        Address address = model.Address;
                        db.Address.Add(address);
                        db.SaveChanges();
                    }
                    return(Json(new { status = "success", message = "آدرس با موفقیت ثبت شد" }));
                }
                else
                {
                    //Update
                    using (var db = _iServiceProvider.GetRequiredService <ApplicationDbContext>())
                    {
                        Address address = model.Address;
                        db.Address.Update(address);
                        db.SaveChanges();
                    }
                    return(Json(new { status = "success", message = "آدرس با موفقیت ویراش شد" }));
                }
            }

            //Display Validation with Jquery Ajax
            var list = new List <string>();

            foreach (var validation in ViewData.ModelState.Values)
            {
                list.AddRange(validation.Errors.Select(error => error.ErrorMessage));
            }

            return(Json(new { status = "error", error = list }));
        }
Example #13
0
        public IActionResult Address(int id)
        {
            MultiModels model = new MultiModels();

            model.AllAddresses = _context.Address.Where(a => a.UserId == _userManager.GetUserId(User)).OrderBy(a => a.AddressId).ToList();

            if (id != 0)//حالت ویرایش
            {
                using (var db = _iServiceProvider.GetRequiredService <ApplicationDbContext>())
                {
                    //Agar peida kard
                    model.Address = _context.Address.Where(c => c.AddressId == id).SingleOrDefault();

                    //Agar peida nakone
                    if (model == null)
                    {
                        return(RedirectToAction("Address"));
                    }
                }
            }
            return(View("Address", model));
        }
Example #14
0
        public IActionResult Details(int id)
        {
            if (id == 0)
            {
                return(RedirectToAction("NotFounds"));
            }

            var model = new MultiModels();


            model.Product = (from p in _context.products where p.ProductId == id select p).SingleOrDefault();
            var categoryId = model.Product.CategoryId;

            var categoryLap       = (from c in _context.categories select c).Where(c => c.Name.Contains("لپ")).SingleOrDefault();
            var categoryCellphone = (from c in _context.categories select c).Where(c => c.Name.Contains("موبایل")).SingleOrDefault();

            if (categoryId == categoryLap.CategoryId)
            {
                model.LaptopDetailViewModel = (from l in _context.laptops
                                               join p in _context.products on l.ProductId equals p.ProductId
                                               where p.ProductId == id
                                               select new LaptopDetailViewModel()
                {
                    ProductId = p.ProductId,
                    LaptopId = l.LaptopId,
                    BatteryType = l.BatteryType,
                    Bluetooth = l.Bluetooth,
                    CpuCache = l.CpuCache,
                    CpuFrequency = l.CpuFrequency,
                    CpuManufactor = l.CpuManufactor,
                    CpuSeries = l.CpuSeries,
                    CpuType = l.CpuType,
                    Description = l.Description,
                    GPUManufactor = l.GPUManufactor,
                    GPUModel = l.GPUModel,
                    GPUSize = l.GPUSize,
                    HDMI = l.HDMI,
                    Modem = l.Modem,
                    ODD = l.ODD,
                    OS = l.OS,
                    OSVersion = l.OSVersion,
                    RAM = l.RAM,
                    RAMType = l.RAMType,
                    ScreenSize = l.ScreenSize,
                    ScreenTechnology = l.ScreenTechnology,
                    ScreenType = l.ScreenType,
                    Size = l.Size,
                    Speaker = l.Speaker,
                    Storage = l.Storage,
                    StorageType = l.StorageType,
                    USB2 = l.USB2,
                    USB3 = l.USB3,
                    VGA = l.VGA,
                    Webcam = l.Webcam,
                    Weight = l.Weight,
                    Wifi = l.Wifi,
                    ProductBrand = p.ProductBrand,
                    ProductDiscount = p.ProductDiscount,
                    ProductImage = p.ProductImage,
                    ProductLikeCount = p.ProductLikeCount,
                    ProductPrice = p.ProductPrice,
                    ProductName = p.ProductName,
                    ProductStock = p.ProductStock,
                    ProductViews = p.ProductViews,
                    ProductDescription = p.ProductDescription,
                    ProductCategory = "لپ‌تاپ",
                    ProductColor = p.ProductColor,
                    ProductWarranty = p.ProductWarranty
                }).SingleOrDefault();
            }

            if (categoryId == categoryCellphone.CategoryId)
            {
                model.CellphoneDetailViewModel = (from c in _context.cellphones
                                                  join p in _context.products on c.ProductId equals p.ProductId
                                                  where p.ProductId == id
                                                  select new CellphoneDetailViewModel()
                {
                    ProductId = p.ProductId,
                    CellphoneId = c.CellphoneId,
                    CameraHas = c.CameraHas,
                    CameraRecording = c.CameraRecording,
                    CameraResolution = c.CameraResolution,
                    ConnectionNetworks = c.ConnectionNetworks,
                    ConnectionTechnologies = c.ConnectionTechnologies,
                    CpuChipset = c.CpuChipset,
                    CpuCore = c.CpuCore,
                    CpuFrequency = c.CpuFrequency,
                    GPU = c.GPU,
                    SimcardCount = c.SimcardCount,
                    CpuType = c.CpuType,
                    ScreenProtector = c.ScreenProtector,
                    SimcardDesc = c.SimcardDesc,
                    StorageSupport = c.StorageSupport,
                    Description = c.Description,
                    OS = c.OS,
                    OSVersion = c.OSVersion,
                    RAM = c.RAM,
                    ScreenSize = c.ScreenSize,
                    ScreenTechnology = c.ScreenTechnology,
                    ScreenType = c.ScreenType,
                    Size = c.Size,
                    Storage = c.Storage,
                    StorageType = c.StorageType,
                    Weight = c.Weight,
                    ProductBrand = p.ProductBrand,
                    ProductDiscount = p.ProductDiscount,
                    ProductImage = p.ProductImage,
                    ProductLikeCount = p.ProductLikeCount,
                    ProductPrice = p.ProductPrice,
                    ProductName = p.ProductName,
                    ProductStock = p.ProductStock,
                    ProductViews = p.ProductViews,
                    ProductDescription = p.ProductDescription,
                    ProductCategory = "گوشی موبایل",
                    ProductColor = p.ProductColor,
                    ProductWarranty = p.ProductWarranty
                }).SingleOrDefault();
            }
            //دستورات تعداد بازدید
            using (var db = _iServiceProvider.GetRequiredService <ApplicationDbContext>())
            {
                var result         = (from b in db.products where b.ProductId == id select b);
                var currentProduct = result.FirstOrDefault();
                if (result.Count() != 0)
                {
                    currentProduct.ProductViews++;
                    //Update Field morede nazar - vaghT faghat bekhaym 1 field o estefade konim az in 2khat estefade mishe
                    db.products.Attach(currentProduct);
                    db.Entry(currentProduct).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            ViewBag.imagepath = "/upload/normalimage/";
            return(View(model));
        }
Example #15
0
        public IActionResult Index()
        {
            var model = new MultiModels();

            model.LastNews = (from n in _context.news orderby n.NewsId descending select n).Take(5).ToList();

            model.PromotionsListViewModel = (from pr in _context.promotion
                                             join p in _context.products on pr.ProductId equals p.ProductId
                                             join c in _context.categories on p.CategoryId equals c.CategoryId
                                             select new PromotionListViewModel()
            {
                ProductName = p.ProductName,
                ProductId = p.ProductId,
                ProductImage = p.ProductImage,
                PromotionId = pr.PromotionId,
                Price = p.ProductPrice
            }).Take(5).ToList();

            List <int> topSellingPId = (from o in _context.OrderDetails
                                        group o by o.ProductId into ts
                                        orderby ts.Count() descending
                                        select ts.Key).Take(5).ToList();

            List <TopSelling> topS = new List <TopSelling>();

            foreach (int id in topSellingPId)
            {
                var m = (from p in _context.products
                         where p.ProductId == id
                         select new TopSelling
                {
                    ProductId = p.ProductId,
                    ProductImage = p.ProductImage,
                    ProductName = p.ProductName,
                    Price = p.ProductPrice
                }).SingleOrDefault();

                topS.Add(m);
            }
            model.TopSellings = topS;

            model.MostViewd = (from p in _context.products
                               orderby p.ProductViews descending
                               select new MostViewd
            {
                ProductName = p.ProductName,
                ProductId = p.ProductId,
                Price = p.ProductPrice,
                ProductImage = p.ProductImage
            }).Take(5).ToList();

            model.Cheapest = (from p in _context.products
                              orderby p.ProductPrice ascending
                              select new Cheapest
            {
                ProductName = p.ProductName,
                ProductId = p.ProductId,
                Price = p.ProductPrice,
                ProductImage = p.ProductImage
            }).Take(5).ToList();

            ViewBag.imagepath = "/upload/normalimage/";
            return(View(model));
        }
Example #16
0
        public IActionResult Index()
        {
            if (_signInManager.IsSignedIn(User))
            {
                var query_find_Name = (from u in _context.Users where u.Id == _userManager.GetUserId(HttpContext.User) select u).SingleOrDefault();
                if (query_find_Name != null)
                {
                    // get name of user
                    ViewBag.fullname = query_find_Name.FirstName + " " + query_find_Name.LastName;
                    // update wallet
                    ViewBag.Wallet = query_find_Name.Wallet;
                }
            }

            ViewBag.imageThumbnail = "/upload/thumbnailimage/";
            ViewBag.normalimage    = "/upload/normalimage/";
            ViewBag.normalnews     = "/upload/normalnews/";
            ViewBag.thumbnailnews  = "/upload/thumbnailnews/";

            //var model = new MultiModels();
            //model._SliderLastBook = (from b in _context.books orderby b.BookId select b).Take(6).ToList();
            //model._SliderLastBook = (from b in _context.books select b).ToList();

            #region _slider
            var model = new MultiModels();
            // select slider (lambda expresion)


            var query = (from b in _context.books
                         orderby b.BookId descending
                         join a in _context.authors on b.AuthorID equals a.AuthorId
                         join bg in _context.bookGroups.Where(bgg => bgg.GropuName == "کودکان") on b.BookGroupID equals bg.BookGroupId
                         select new
            {
                b.BookId,
                b.BookName,
                b.PageNumber,
                b.Image,
                b.AuthorID,
                b.BookGroupID,
                a.AuthorName,
                bg.GropuName
            }).Take(6).ToList();

            foreach (var item in query)
            {
                BookListViewModel temps = new BookListViewModel();
                temps.BookId        = item.BookId;
                temps.BookName      = item.BookName;
                temps.PageNumber    = item.PageNumber;
                temps.BookImage     = item.Image;
                temps.AuthorId      = item.AuthorID;
                temps.BookGroupId   = item.BookGroupID;
                temps.AuthorName    = item.AuthorName;
                temps.BookGroupName = item.GropuName;
                if (temps != null)
                {
                    model._SliderLastBook.Add(temps);
                }
            }

            #endregion

            #region _LastMoreVisit
            //model._LastMoreVisit = (from b in _context.books where b.BookGroupID == 2 orderby b.BookId descending select b).Take(6).ToList();
            model._LastMoreVisit = (from b in _context.books select b).OrderBy(indexBook => indexBook.BookViews).Take(6).ToList();
            #endregion

            #region _LastRegisterUser
            model._LastRegisterUser = (from u in _userManager.Users orderby u.Id descending select u).Take(10).ToList();
            #endregion

            #region _LastNews
            // get last 6 news
            model._LastNews = (from n in _context.news select n).OrderByDescending(m => m.newsDate).Take(6).ToList();
            #endregion

            #region more view
            model.moreViewBook = (from b in _context.books orderby b.BookViews descending select b).Take(6).ToList();
            #endregion

            return(View(model));
        }