Exemple #1
0
        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));
                }
            }
        }