Esempio n. 1
0
        public async Task <IActionResult> Create(ProductPhoto productPhoto)
        {
            if (productPhoto.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    productPhoto.Photo = fileManager.Upload(productPhoto.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(productPhoto);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Məhsul üçün Şəkil Əlavə olundu";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", productPhoto.ProductId);
            return(View(productPhoto));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(AdminViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_db.Users.Any(x => x.Email == model.Email))
                {
                    TempData["Error"] = "Bu E-Poçt ünvanı artıq Qeydiyyatdan keçmişdir!";

                    return(View());
                }
                AppAdmin admin = new AppAdmin
                {
                    Email     = model.Email,
                    Birthday  = new DateTime(2000, 01, 01),
                    Firstname = "Admin",
                    Lastname  = "Admin",
                    UserName  = "******" + Guid.NewGuid()
                };
                await _userManager.CreateAsync(admin);

                await _db.SaveChangesAsync();

                TempData["Success"] = "Yeni Admin uğurla yaradıldı və " + model.Email + " ünvanına Qeydiyyyat üçün Mail Göndərildi!";
                SendMail mail = new SendMail();
                mail.SendEmail(admin);
                return(RedirectToAction(nameof(Index)));
            }

            return(View("index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Review(BlogReview review)
        {
            if (ModelState.IsValid)
            {
                if (review.AdminManagerId == 0)
                {
                    review.AdminManagerId = null;
                }
                if (review.UserClientId == 0)
                {
                    review.UserClientId = null;
                }
                if (review.AdminManagerId == null && review.UserClientId == null)
                {
                    return(Json(new { status = false }));
                }
                review.CreatedAt = DateTime.Now;
                await _db.BlogReviews.AddAsync(review);

                await _db.SaveChangesAsync();

                BlogReview model = await _db.BlogReviews.Include("User").FirstOrDefaultAsync(x => x.Id == review.Id);

                return(PartialView("_BlogReview", model));
            }

            return(Json(new { status = false }));
        }
Esempio n. 4
0
        // Add Cart
        public async Task <IActionResult> Add(int id, int colorId = 1)
        {
            Product product = await _db.Products.Include("ProductPhotos").Include("ProductColors.Color").FirstOrDefaultAsync(a => a.Id == id);

            List <CartItem> cart     = HttpContext.Session.GetJson <List <CartItem> >("Cart") ?? new List <CartItem>();
            CartItem        cartItem = cart.FirstOrDefault(x => x.ProductId == id && x.ColorId == colorId);
            Color           color    = await _db.Colors.FirstOrDefaultAsync(x => x.Id == colorId);

            int MostFollowed = (int)_db.Products.Where(x => x.Status == true).OrderByDescending(x => x.FollowCount).FirstOrDefault().FollowCount;
            int ThisFollowd  = (int)product.FollowCount;

            product.StarCount = (ThisFollowd * 5 / MostFollowed);
            if (cartItem == null)
            {
                cart.Add(new CartItem(product, color));
            }
            else
            {
                cartItem.Quantity += 1;
            }
            await _db.SaveChangesAsync();

            HttpContext.Session.SetJson("Cart", cart);
            if (HttpContext.Request.Headers["x-requested-with"] != "XMLHttpRequest")
            {
                return(Redirect((!string.IsNullOrEmpty(Request.Headers["Referer"]) ? Request.Headers["Referer"].ToString() : "/")));
            }

            return(ViewComponent("SmallCart"));
        }
Esempio n. 5
0
        public async Task <IActionResult> Detail(string slug)
        {
            if (slug == null)
            {
                return(RedirectToAction("error", "home"));
            }
            AdminManager admin       = new AdminManager();
            UserClient   user        = new UserClient();
            var          cookieUser  = Request.Cookies["Token"];
            var          cookieAdmin = Request.Cookies["TokenAdmin"];

            if (cookieAdmin != null)
            {
                admin = await _db.AdminManagers.FirstOrDefaultAsync(a => a.Token == cookieAdmin);
            }
            if (cookieUser != null)
            {
                user = await _db.UserClients.FirstOrDefaultAsync(a => a.Token == cookieUser);
            }
            var     rqf     = Request.HttpContext.Features.Get <IRequestCultureFeature>();
            var     culture = rqf.RequestCulture.Culture;
            Product product = await _db.Products.Include("ProductTranslates").Include("ProductPhotos").Include("ProductColors.Color").Include("BrandProductCategory.ProductSubCategory.ProductSubCategoryTranslate").Include("ProperityProducts.Properity.ProperityTranslates").FirstOrDefaultAsync(p => p.Status == true && p.Slug == slug);

            Product productReview = await _db.Products.Include("ProductReviews.User").Include("ProductReviews.Admin.Category.AdminCategoryTranslates").FirstOrDefaultAsync(p => p.Status == true && p.Slug == slug);

            if (product == null)
            {
                return(RedirectToAction("error", "home"));
            }
            ShopDetailVM model = new ShopDetailVM
            {
                UserClientId = (user != null ? user.Id : 0),
                AdminId      = (admin != null ? admin.Id : 0),
                Breadcrumb   = new Breadcrumb
                {
                    Path = new Dictionary <string, string> {
                        { "Home", Url.Action("Index", "Home") },
                        { "Product Detail", null }
                    },
                    Page = Page.ShopDetail
                },
                LanguageId        = _db.Languages.FirstOrDefault(l => l.LanguageCode == culture.ToString()).Id,
                Product           = product,
                ProductReview     = productReview,
                LikeProducts      = await _db.Products.Include("BrandProductCategory.ProductSubCategory.ProductSubCategoryTranslate.Language").Include("ProductPhotos").Where(p => p.Status == true && p.BrandProductCategory.ProductSubCategoryId == product.BrandProductCategory.ProductSubCategoryId).ToListAsync(),
                MostSaledProducts = await _db.Products.Include("BrandProductCategory.ProductSubCategory.ProductSubCategoryTranslate").Include("ProductPhotos").Where(p => p.Status == true).OrderBy(o => o.CreatedAt).ToListAsync()
            };

            if (User?.Identity?.IsAuthenticated == false)
            {
                model.Product.FollowCount++;
                await _db.SaveChangesAsync();
            }


            return(View(model));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Code,Status,CreatedAt")] Color color)
        {
            if (ModelState.IsValid)
            {
                _context.Add(color);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(color));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("Name,Slug,Status,CreatedAt,Id,AdminManagerId,ModifiedAt")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brand);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Yeni Brend uğurla yaradıldı";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"] = new SelectList(_context.AdminManagers, "Id", "Email", brand.AdminManagerId);
            return(View(brand));
        }
Esempio n. 8
0
        public async Task <IActionResult> Create(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                Product prod = _context.Products.FirstOrDefault(x => x.Name.ToLower() == model.Product.Name.ToLower());
                if (prod != null)
                {
                    model.BrandProductCategories       = _context.BrandProductCategories.Include("Brand").Include("ProductSubCategory.ProductSubCategoryTranslate").ToList();
                    TempData["Error"]                  = "Bu adda məhsul artıq mövcuddur!";
                    ViewData["BrandProductCategoryId"] = new SelectList(_context.BrandProductCategories, "Id", "Id", model.Product.BrandProductCategoryId);
                    return(View(model));
                }
                _context.Add(model.Product);
                await _context.SaveChangesAsync();

                foreach (var product in model.ProductTranslates)
                {
                    product.ProductId = _context.Products.FirstOrDefault(x => x.Name == model.Product.Name && x.CreatedAt == model.Product.CreatedAt).Id;
                    _context.Add(product);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Məhsul Yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            model.BrandProductCategories       = _context.BrandProductCategories.Include("Brand").Include("ProductSubCategory.ProductSubCategoryTranslate").ToList();
            ViewData["BrandProductCategoryId"] = new SelectList(_context.BrandProductCategories, "Id", "Id", model.Product.BrandProductCategoryId);
            return(View(model));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create(BlogViewModel model)
        {
            if (model.Blog.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    model.Blog.Photo = fileManager.Upload(model.Blog.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(model.Blog);
                await _context.SaveChangesAsync();

                foreach (var blog in model.BlogTranslates)
                {
                    blog.BlogId = _context.Blogs.FirstOrDefault(x => x.Photo == model.Blog.Photo && x.CreatedAt == model.Blog.CreatedAt).Id;
                    _context.Add(blog);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Xəbər yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public async Task <IActionResult> Create(HomeHeaderViewModel model)
        {
            if (model.HomeHeader.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(webHostEnvironment);
                    model.HomeHeader.Photo = fileManager.Upload(model.HomeHeader.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(model.HomeHeader);
                await _context.SaveChangesAsync();

                foreach (var homeHeader in model.HomeHeaderTranslates)
                {
                    homeHeader.HomeHeaderId = _context.HomeHeaders.FirstOrDefault(x => x.Photo == model.HomeHeader.Photo && x.ModifiedAt == model.HomeHeader.ModifiedAt).Id;
                    _context.Add(homeHeader);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Ana Səhifə Başlığı yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", model.HomeHeader.ProductId);
            return(View(model));
        }
        public async Task <IActionResult> Create(ProperityProduct properityProduct)
        {
            if (ModelState.IsValid)
            {
                ProperityProduct properity = _context.ProperityProducts.FirstOrDefault(x => x.ProductId == properityProduct.ProductId && x.ProperityId == properityProduct.ProperityId);
                if (properity != null)
                {
                    TempData["Error"]       = "Artiq Bu Məhsul üçün Xüsusiyyət seçilib";
                    ViewData["ProductId"]   = new SelectList(_context.Products, "Id", "Name", properityProduct.ProductId);
                    ViewData["ProperityId"] = new SelectList(_context.ProperityTranslates.Where(x => x.LanguageId == 2), "ProperityId", "Name", properityProduct.ProperityId);
                    return(View(properityProduct));
                }
                _context.Add(properityProduct);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Məhsul üçün Xüsusiyyət uğurla seçildi";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"]   = new SelectList(_context.Products, "Id", "Name", properityProduct.ProductId);
            ViewData["ProperityId"] = new SelectList(_context.ProperityTranslates.Where(x => x.LanguageId == 2), "ProperityId", "Name", properityProduct.ProperityId);
            return(View(properityProduct));
        }
Esempio n. 12
0
        public async Task <IActionResult> Index(LoginVM model, string returnUrl = "/")
        {
            if (ModelState.IsValid)
            {
                UserClient user = await _db.UserClients.FirstOrDefaultAsync(a => a.Email == model.Login.Email);

                PasswordHasher <UserClient> hasher = new PasswordHasher <UserClient>(
                    new OptionsWrapper <PasswordHasherOptions>(
                        new PasswordHasherOptions()
                {
                    CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2
                })
                    );
                var result = hasher.VerifyHashedPassword(user, user.Password, model.Login.Password);

                if (user != null && result == PasswordVerificationResult.Success)
                {
                    user.Token = Guid.NewGuid().ToString();
                    await _db.SaveChangesAsync();

                    var option = new CookieOptions {
                        Expires     = DateTime.Now.AddMinutes(60),
                        IsEssential = true
                    };
                    Response.Cookies.Append("Token", user.Token, option);

                    return(LocalRedirect(returnUrl));
                }
            }
            model.Breadcrumb = new Breadcrumb
            {
                Path = new Dictionary <string, string> {
                    { "Home", Url.Action("Index", "Home") },
                    { "Register", null }
                },
                Page = Page.Login
            };
            return(View(model));
        }
Esempio n. 13
0
        public async Task <IActionResult> Create([Bind("Id,BrandId,ProductSubCategoryId")] BrandProductCategory brandProductCategory)
        {
            if (ModelState.IsValid)
            {
                BrandProductCategory brandProduct = _context.BrandProductCategories.FirstOrDefault(x => x.ProductSubCategoryId == brandProductCategory.ProductSubCategoryId && x.BrandId == brandProductCategory.BrandId);
                if (brandProduct != null)
                {
                    TempData["Error"] = "Artiq Bu Brend üçün Kateqoriya seçilib";

                    ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "Name", brandProductCategory.BrandId);
                    ViewData["ProductSubCategoryId"] = new SelectList(_context.ProductCategoryTranslates.Where(x => x.LanguageId == 2), "ProductCategoryId", "Name", brandProductCategory.ProductSubCategoryId);
                    return(View(brandProductCategory));
                }
                _context.Add(brandProductCategory);
                await _context.SaveChangesAsync();

                TempData["Success"] = "Brend üçün Kateqoriya uğurla seçildi";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "Name", brandProductCategory.BrandId);
            ViewData["ProductSubCategoryId"] = new SelectList(_context.ProductCategoryTranslates.Where(x => x.LanguageId == 2), "ProductCategoryId", "Name", brandProductCategory.ProductSubCategoryId);
            return(View(brandProductCategory));
        }
Esempio n. 14
0
        public async Task <IActionResult> Edit(int id, SettingViewModel model)
        {
            if (id != model.Setting.Id)
            {
                return(NotFound());
            }
            if (model.Setting.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(webHostEnvironment);
                    model.Setting.PhotoLogo = fileManager.Upload(model.Setting.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                foreach (var setTranslate in model.SettingTranslates)
                {
                    _context.Update(setTranslate);
                }
                try
                {
                    model.Setting.ModifiedAt = DateTime.Now;
                    _context.Update(model.Setting);
                    await _context.SaveChangesAsync();

                    TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SettingExists(model.Setting.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"] = new SelectList(_context.AdminManagers, "Id", "Email", model.Setting.AdminManagerId);
            return(View(model));
        }
Esempio n. 15
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var userClient = await _context.UserClients
                             .FirstOrDefaultAsync(m => m.Id == id);

            if (userClient == null)
            {
                return(NotFound());
            }
            _context.UserClients.Remove(userClient);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var orderProduct = await _context.OrderProducts
                               .Include(o => o.Product)
                               .Include(o => o.User)
                               .FirstOrDefaultAsync(m => m.Id == id);

            if (orderProduct == null)
            {
                return(NotFound());
            }
            _context.OrderProducts.Remove(orderProduct);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var productReview = await _context.ProductReviews
                                .Include(p => p.Admin)
                                .Include(p => p.Product)
                                .Include(p => p.User)
                                .FirstOrDefaultAsync(m => m.Id == id);

            if (productReview == null)
            {
                return(NotFound());
            }
            _context.ProductReviews.Remove(productReview);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(ProperityViewModel model)
        {
            if (ModelState.IsValid)
            {
                _context.Add(model.Properity);
                await _context.SaveChangesAsync();

                foreach (var properity in model.ProperityTranslates)
                {
                    properity.ProperityId = _context.Properities.FirstOrDefault(x => x.CreatedAt == model.Properity.CreatedAt).Id;
                    _context.Add(properity);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Xüsusiyyət yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Esempio n. 19
0
        public async Task <IActionResult> Create(ProductSubCategoryViewModel model)
        {
            if (_context.ProductSubCategoryTranslates.Any(x => x.Name.ToLower() == model.ProductSubCategoryTranslates[1].Name.ToLower()))
            {
                ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
                ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "Id", "Id", model.ProductSubCategory.ProductCategoryId);
                TempData["Error"]             = "Bu adda Alt kateqoriya mövcuddur!";
                return(View(model));
            }
            if (model.ProductSubCategory.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    model.ProductSubCategory.Photo = fileManager.Upload(model.ProductSubCategory.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                model.ProductSubCategory.CreatedAt  = DateTime.Now;
                model.ProductSubCategory.ModifiedAt = DateTime.Now;
                model.ProductSubCategory.Status     = true;
                _context.Add(model.ProductSubCategory);
                await _context.SaveChangesAsync();

                foreach (var productSubCategory in model.ProductSubCategoryTranslates)
                {
                    productSubCategory.ProductSubCategoryId = _context.ProductSubCategories.FirstOrDefault(x => x.Photo == model.ProductSubCategory.Photo && x.CreatedAt == model.ProductSubCategory.CreatedAt).Id;
                    _context.Add(productSubCategory);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Alt kateqoriya yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
            ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "Id", "Id", model.ProductSubCategory.ProductCategoryId);
            return(View(model));
        }