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 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")); }
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")); }
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()); }