public ActionResult Ekle(Slider model, HttpPostedFileBase SliderResim) { ModelState.Remove("SliderYol"); if (ModelState.IsValid) { if (SliderResim != null && (SliderResim.ContentType == "image/jpeg" || SliderResim.ContentType == "image/jpg" || SliderResim.ContentType == "image/png")) { string filename = $"{AdGetir.ResimAd(model.SliderBaslik)}.{SliderResim.ContentType.Split('/')[1]}"; SliderResim.SaveAs(Server.MapPath($"~/img/Slider/{filename}")); //string filename = ResimKayit(SliderResim, "LinkLogo", model.LinkAdi); model.SliderYol = filename; } else { ModelState.AddModelError("", "Resim Formatı JPG veya PNG olmalıdır"); return(View(model)); } var result = _managerSlider.Insert(model); if (result == 0) { ModelState.AddModelError("", "Slider Ekleme İşlemi Başarısız oldu"); return(View(model)); } return(RedirectToAction("Index")); } return(View(model)); }
protected void SaveData() { if (this.ddlCategory.SelectedValue == "0") { this.lblError.Text = "Hãy chọn kiểu"; return; } try { if (id > 0) { SliderInfo info = new SliderInfo(); info.SliderName = txtName.Text.Trim(); info.SliderContent = txtDetailText.Value; info.SliderImage = imageName; info.SliderLink = txtLink.Text.Trim(); info.SliderClass = ddlCategory.SelectedValue.ToString(); info.SliderID = id; SliderManager.Update(info); } else { //this is a new object. SliderInfo info = new SliderInfo(); info.SliderName = txtName.Text.Trim(); info.SliderContent = txtDetailText.Value; info.SliderImage = imageName; info.SliderLink = txtLink.Text.Trim(); info.SliderClass = ddlCategory.SelectedValue.ToString(); SliderManager.Insert(info); } this.lblError.Text = "Đã lưu dữ liệu thành công"; } catch (Exception ex) { this.lblError.Text = ex.Message; } }
public ActionResult SaveDataInDatabase(Slider slider, HttpPostedFileBase file) { using (SliderManager sliderManager = new SliderManager()) { int result = -1; if (ModelState.IsValid) { if (slider.Id > 0) { var sliderItems = sliderManager.Find(x => x.Id == slider.Id); BusinessLayerResult <Slider> res = sliderManager.priorityControlUpdate(slider); if (res.Errors.Count > 0) { ErrorViewModel errorObj = new ErrorViewModel() { Items = res.Errors, Tittle = "Slider Güncellenemedi...", RedirectingUrl = "/Admin/Slider/Index/" + slider.Id, }; return(View("AdminError", errorObj)); } var deleted = HttpContext.Server.MapPath("~" + sliderItems.imageUrl); sliderItems.Name = slider.Name; sliderItems.Url = slider.Url; if (file != null) { if (System.IO.File.Exists(deleted)) { System.IO.File.Delete(deleted); } FileHelper filehelper = new FileHelper(); var mpath = Server.MapPath("~/Images/Slider"); sliderItems.imageUrl = filehelper.SaveImage(file, mpath, "/Images/Slider"); } //editUrun.UrunResimUrl = @"/Images/Product/" + editUrun.UrunID; sliderItems.isActive = slider.isActive; sliderItems.Priority = slider.Priority; if (sliderManager.Update(sliderItems) > 0) { result = 1; } } else { BusinessLayerResult <Slider> res = sliderManager.priorityControlInsert(slider); if (res.Errors.Count > 0) { ErrorViewModel errorObj = new ErrorViewModel() { Items = res.Errors, Tittle = "Slider Eklenemedi...", RedirectingUrl = "/Admin/Slider/Index", }; return(View("AdminError", errorObj)); } if (file != null) { FileHelper filehelper = new FileHelper(); var mpath = Server.MapPath("~/Images/Slider"); slider.imageUrl = filehelper.SaveImage(file, mpath, "/Images/Slider"); } sliderManager.Insert(slider); //var model = sliderManager.ListQueryable().Where(x => !x.isDeleted).OrderBy(x => x.Priority).ToList(); result = 2; } return(Json(result, JsonRequestBehavior.AllowGet)); } else { return(View(slider)); } } }