public ActionResult DeletePost(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var DeleteNews = db.News.FirstOrDefault(f => f.Id == id);

                if (DeleteNews == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    var imgName = Path.GetFileName(DeleteNews.ImagePath);
                    var imgPath = ProsesImageFile.ImagePath(imgName, "/Image/News");
                    ProsesImageFile.DeleteImageFile(imgPath);

                    db.News.Remove(DeleteNews);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
        }
        public async Task <ActionResult> Create(NewsDbModel createNews)
        {
            if (ModelState.IsValid)
            {
                if (createNews.NewsImg != null && createNews.NewsImg.ContentLength > 0)
                {
                    var ImgNewName   = ProsesImageFile.FileName(createNews.NewsImg);
                    var ImgsavedPath = ProsesImageFile.ImagePath(ImgNewName, "/Image/News");
                    createNews.NewsImg.SaveAs(ImgsavedPath);

                    if (createNews.NewsCreateDate == null)
                    {
                        createNews.NewsCreateDate = DateTime.Now;
                    }

                    createNews.IsActive  = Convert.ToBoolean(createNews.Activ);//????
                    createNews.ImagePath = "/Image/News/" + ImgNewName;
                    db.News.Add(createNews);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                return(HttpNotFound());
            }
            else
            {
                return(View(createNews));
            }
        }
        public ActionResult Delete(int?Id)
        {
            if (Id == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var DeleteCarusel = db.Carusels.FirstOrDefault(f => f.Id == Id);

                if (DeleteCarusel == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    var imgName = Path.GetFileName(DeleteCarusel.ImagePath);
                    var imgPath = ProsesImageFile.ImagePath(imgName, "/Image/Carusel");
                    ProsesImageFile.DeleteImageFile(imgPath);

                    db.Carusels.Remove(DeleteCarusel);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
        }
        public ActionResult Edit(CaruselView EditCarusel)
        {
            if (ModelState.IsValid)
            {
                var EditCaruselDb = db.Carusels.FirstOrDefault(f => f.Id == EditCarusel.Id);
                if (EditCaruselDb == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    var imgName   = ProsesImageFile.FileName(EditCarusel.File);
                    var imgPath   = ProsesImageFile.ImagePath(imgName, "/Image/Carusel");
                    var imgasName = Path.GetFileName(imgPath);
                    EditCarusel.File.SaveAs(imgPath);

                    EditCaruselDb.Text      = EditCarusel.Text;
                    EditCaruselDb.Title     = EditCarusel.Title;
                    EditCaruselDb.IsActive  = EditCarusel.IsActive;
                    EditCaruselDb.ImagePath = "/Image/Carusel/" + imgName;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
Exemple #5
0
 public ActionResult DeletePost(int id)
 {
     try
     {
         var deletShop = db.Shops.FirstOrDefault(f => f.Id == id);
         var imgName   = Path.GetFileName(deletShop.ImagePath);
         var imgPath   = ProsesImageFile.ImagePath(imgName, "/Image/Shops");
         ProsesImageFile.DeleteImageFile(imgPath);
         db.Shops.Remove(deletShop);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(HttpNotFound());
     }
 }
Exemple #6
0
 public ActionResult DeletePost(int id)
 {
     try
     {
         var deletCountry = db.Countries.FirstOrDefault(f => f.Id == id);
         var imgName      = Path.GetFileName(deletCountry.ImagePath);
         var imgPath      = ProsesImageFile.ImagePath(imgName, "/Image/Country");
         if (System.IO.File.Exists(imgPath))
         {
             ProsesImageFile.DeleteImageFile(imgPath);
         }
         db.Countries.Remove(deletCountry);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(HttpNotFound());
     }
 }
Exemple #7
0
 public ActionResult Edit(Setting edit)
 {
     if (ModelState.IsValid)
     {
         if (edit.TitleImage != null && edit.TitleImage.ContentLength > 0)
         {
             var imgName   = ProsesImageFile.FileName(edit.TitleImage);
             var ImagePath = ProsesImageFile.ImagePath(imgName, "/Image/Settings");
             edit.TitleImage.SaveAs(ImagePath);
             edit.TitleImagePath = "/Image/Settings/" + imgName;
         }
         db.Entry(edit).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }
        public ActionResult Create(CaruselView NewCarusel)
        {
            if (ModelState.IsValid)
            {
                CaruselDb newDbCarusel = new CaruselDb();

                var imgName = ProsesImageFile.FileName(NewCarusel.File);
                var imgPath = ProsesImageFile.ImagePath(imgName, "/Image/Carusel");
                NewCarusel.File.SaveAs(imgPath);

                newDbCarusel.Text      = NewCarusel.Text;
                newDbCarusel.Title     = NewCarusel.Title;
                newDbCarusel.IsActive  = false;
                newDbCarusel.ImagePath = "/Image/Carusel/" + imgName;
                db.Carusels.Add(newDbCarusel);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
Exemple #9
0
 public ActionResult Create(Setting create)
 {
     if (ModelState.IsValid)
     {
         if (create.TitleImage != null && create.TitleImage.ContentLength > 0)
         {
             var imgName   = ProsesImageFile.FileName(create.TitleImage);
             var ImagePath = ProsesImageFile.ImagePath(imgName, "/Image/Settings");
             create.TitleImage.SaveAs(ImagePath);
             create.TitleImagePath = "/Image/Settings/" + imgName;
         }
         else
         {
             create.TitleImagePath = null;
         }
         db.Settings.Add(create);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(HttpNotFound());
 }