public async Task <IActionResult> SingleProduct(string code) { using var context = new EsramDbContext(); var prod = await context.Products.Include(x => x.Pictures).Include(x => x.Category).ThenInclude(x => x.MasterCategory).FirstOrDefaultAsync(x => x.Code == code); return(View(prod)); }
public async Task <IActionResult> EditPictures(IFormFile MainPicture, List <IFormFile> Pictures, int productId) { using var context = new EsramDbContext(); Product prod = await context.Products.FindAsync(productId); if (MainPicture != null) { if (prod.MainPicture != null) { FileExtension.RemoveFile(prod.MainPicture); } prod.MainPicture = FileExtension.UploadFile(MainPicture, "wwwroot/static/uploads/products").Replace(@"\", "/"); context.Products.Update(prod); } if (Pictures.Count > 0) { List <ProductPicture> pList = new List <ProductPicture>(); foreach (var pic in Pictures) { pList.Add(new ProductPicture { Path = FileExtension.UploadFile(pic, "wwwroot/static/uploads/products").Replace(@"\", "/"), ProductId = productId }); } await context.ProductPictures.AddRangeAsync(pList); } await context.SaveChangesAsync(); return(RedirectToAction("EditProduct", prod)); }
public async Task <IActionResult> Index() { using var context = new EsramDbContext(); var mcs = await context.MasterCategories.Include(m => m.Categories).ToListAsync(); return(View(mcs)); }
public async Task <IActionResult> EditProduct(int id) { using var context = new EsramDbContext(); var product = await context.Products.Include(x => x.Pictures).FirstOrDefaultAsync(x => x.Id == id); return(View(product)); }
public async Task <IActionResult> GetCategoriesByMaster(int mcid) { using var context = new EsramDbContext(); var cats = await context.Categories.Where(x => x.MasterCategoryId == mcid).OrderByDescending(x => x.Id).ToListAsync(); return(Json(cats)); }
public async Task <IActionResult> EditModal(int mcid) { using var context = new EsramDbContext(); var mc = await context.MasterCategories.FirstOrDefaultAsync(x => x.Id == mcid); return(ViewComponent("EditModal", mc)); }
public async Task <IActionResult> EditCategoryModal(int cid) { using var context = new EsramDbContext(); var cat = await context.Categories.FirstOrDefaultAsync(x => x.Id == cid); return(ViewComponent("EditCategoryModal", cat)); }
public async Task <IActionResult> Index() { using var context = new EsramDbContext(); var sliders = await context.Sliders.OrderBy(x => x.Index).ToListAsync(); return(View(sliders)); }
public async Task <IActionResult> EditProduct(Product product) { using var context = new EsramDbContext(); var current = await context.Products.Include(x => x.Pictures).FirstOrDefaultAsync(x => x.Id == product.Id); if (ModelState.IsValid) { current.Name = product.Name; current.IsBest = product.IsBest; current.MainPicture = product.MainPicture; current.Code = product.Code; current.Price = product.Price; current.Description = product.Description; context.Products.Update(current); int result = await context.SaveChangesAsync(); if (result > 0) { ViewBag.Success = "Ürün başarıyla güncellendi"; } else { ViewBag.Error = "Ürün güncellenirken bir hata oluştu"; } } return(View(current)); }
public IViewComponentResult Invoke() { using var context = new EsramDbContext(); var bests = context.Products.Include(x => x.Category).ThenInclude(x => x.MasterCategory).Where(x => x.IsBest).OrderByDescending(x => x.Id).ToListAsync().Result; return(View("~/Views/ViewComponents/homebestarea.cshtml", bests)); }
public IViewComponentResult Invoke(int productId) { using var context = new EsramDbContext(); var p = context.Products.Include(x => x.Pictures).Include(x => x.Category).FirstOrDefault(p => p.Id == productId); return(View("~/Views/ViewComponents/productmodal.cshtml", p)); }
public IViewComponentResult Invoke() { using var context = new EsramDbContext(); var mcs = context.MasterCategories.Include(x => x.Categories).OrderBy(x => x.Index).ToList(); return(View("~/Views/Shared/header.cshtml", mcs)); }
public async Task <IActionResult> Faq() { using var context = new EsramDbContext(); var faqs = await context.Faqs.OrderByDescending(x => x.Id).ToListAsync(); return(View(faqs)); }
public IActionResult ChangePassword(string currentPassword, string password, string confirmPassword) { Dictionary <string, object> result = new Dictionary <string, object>(); var id = Convert.ToInt32(HttpContext.Request.Cookies["_edul"]); using var context = new EsramDbContext(); var user = context.Users.Find(id); if (currentPassword == user.Password) { if (password == confirmPassword) { user.Password = password; context.Users.Update(user); context.SaveChanges(); result.Add("status", true); result.Add("message", "Şifreniz başarıyla değiştirildi"); } else { result.Add("status", false); result.Add("message", "Yeni şifreler eşleşmiyor"); } } else { result.Add("status", false); result.Add("message", "Mevcut şifre yanlış girildi"); } return(Json(result)); }
public async Task <IActionResult> CreateProduct(Product product, IFormFile MainPicture, List <IFormFile> Pictures) { CreateProductViewModel vm = new CreateProductViewModel(); using var context = new EsramDbContext(); vm.MasterCategories = context.MasterCategories.Include(x => x.Categories).ToList(); vm.Product = new Product(); if (ModelState.IsValid) { product.MainPicture = FileExtension.UploadFile(MainPicture, "wwwroot/static/uploads/products").Replace(@"\", "/"); if (Pictures.Count > 0) { product.Pictures = new List <ProductPicture>(); foreach (var item in Pictures) { product.Pictures.Add(new ProductPicture { Path = FileExtension.UploadFile(item, "wwwroot/static/uploads/products").Replace(@"\", "/") }); } } await context.Products.AddAsync(product); int result = await context.SaveChangesAsync(); ViewBag.Success = "Ürün başarıyla eklendi"; return(View(vm)); } return(View(vm)); }
public IViewComponentResult Invoke(int mcid = 0) { using var context = new EsramDbContext(); mcid = mcid == 0 ? context.MasterCategories.FirstOrDefault().Id : mcid; var products = context.Products.Include(x => x.Category).ThenInclude(x => x.MasterCategory).Where(x => x.Category.MasterCategoryId == mcid).OrderByDescending(x => x.Id).Take(12).ToListAsync().Result; return(View("~/Views/ViewComponents/hometabarea.cshtml", products)); }
public IActionResult CreateProduct() { using var context = new EsramDbContext(); CreateProductViewModel vm = new CreateProductViewModel(); vm.Product = new Product(); vm.MasterCategories = context.MasterCategories.Include(x => x.Categories).ToList(); return(View(vm)); }
public async Task <IActionResult> DeleteCategory(int cid) { using var context = new EsramDbContext(); var cat = await context.Categories.FirstOrDefaultAsync(x => x.Id == cid); context.Categories.Remove(cat); int result = await context.SaveChangesAsync(); return(result > 0?Json(true):Json(false)); }
public async Task <IActionResult> DeleteMasterCategory(int id) { using var context = new EsramDbContext(); var mc = await context.MasterCategories.FirstOrDefaultAsync(x => x.Id == id); context.MasterCategories.Remove(mc); await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteProduct(int pid) { using var context = new EsramDbContext(); var prod = await context.Products.FindAsync(pid); context.Products.Remove(prod); int result = await context.SaveChangesAsync(); return(Json(result > 0)); }
public async Task <IActionResult> Index() { using var context = new EsramDbContext(); HomeViewModel vm = new HomeViewModel(); vm.MasterCategories = await context.MasterCategories.ToListAsync(); vm.Sliders = await context.Sliders.OrderBy(x => x.Index).ToListAsync(); return(View(vm)); }
public async Task <IActionResult> DeleteGallery(int gid) { using var context = new EsramDbContext(); ProductPicture pic = await context.ProductPictures.FindAsync(gid); context.ProductPictures.Remove(pic); FileExtension.RemoveFile(pic.Path); int result = await context.SaveChangesAsync(); return(Json(result > 0)); }
public async Task <IActionResult> AddMasterCategory(MasterCategory masterCategory, IFormFile McPicturePath) { if (McPicturePath != null) { masterCategory.PicturePath = FileExtension.UploadFile(McPicturePath, "wwwroot/static/uploads/categories").Replace(@"\", "/"); } using var context = new EsramDbContext(); context.MasterCategories.Add(masterCategory); int result = await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> EditCategory(Category cat, IFormFile PicturePath) { if (PicturePath != null) { cat.PicturePath = FileExtension.UploadFile(PicturePath, "wwwroot/static/uploads/categories").Replace(@"\", "/"); } using var context = new EsramDbContext(); context.Categories.Update(cat); await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Index() { using var context = new EsramDbContext(); var categories = await context.MasterCategories.Include(x => x.Categories).OrderByDescending(x => x.Id).ToListAsync(); CategoryViewModel vm = new CategoryViewModel { MasterCategories = categories, MasterCategory = new MasterCategory() }; return(View(vm)); }
public async Task <IActionResult> ShopByMasterCategory(string mastercategory, int pageIndex = 1) { using var context = new EsramDbContext(); ShopIndexViewModel vm = new ShopIndexViewModel(); vm.Products = await context.Products.Where(x => x.Category.MasterCategory.Name == mastercategory).OrderByDescending(x => x.Id).Skip((pageIndex - 1) * 12).Take(12).ToListAsync(); vm.MasterCategories = await context.MasterCategories.Include(x => x.Categories).OrderByDescending(x => x.Id).ToListAsync(); ViewBag.MasterCategory = mastercategory; ViewBag.PageIndex = pageIndex; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(await context.Products.Where(x => x.Category.MasterCategory.Name == mastercategory).CountAsync()) / Convert.ToDouble(12)); return(View("~/Views/Shop/Index.cshtml", vm)); }
public async Task <IActionResult> NewSlider(int index, IFormFile path) { using var context = new EsramDbContext(); var slider = new Slider { Index = index, Path = FileExtension.UploadFile(path, "wwwroot/static/uploads/sliders").Replace(@"\", "/") }; context.Sliders.Add(slider); await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> EditSlider(int id, int index, IFormFile path, string currentpath) { using var context = new EsramDbContext(); var slider = await context.Sliders.FindAsync(id); slider.Index = index; if (path != null) { slider.Path = FileExtension.UploadFile(path, "wwwroot/static/uploads/sliders").Replace(@"\", "/"); } context.Sliders.Update(slider); await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteSlider(int sid) { using var context = new EsramDbContext(); var slider = await context.Sliders.FirstOrDefaultAsync(x => x.Id == sid); context.Sliders.Remove(slider); int result = await context.SaveChangesAsync(); if (result > 0) { FileExtension.RemoveFile(slider.Path); return(Json(true)); } return(Json(false)); }
public IViewComponentResult Invoke(int sid = 0) { using var context = new EsramDbContext(); var slider = new Slider(); if (sid != 0) { slider = context.Sliders.Find(sid); } else { slider = context.Sliders.OrderBy(x => x.Index).FirstOrDefault(); } return(View("~/Areas/ritapanel/Views/ViewComponents/slidercard.cshtml", slider)); }