Пример #1
0
        // ADD: Slider

        public ActionResult AddSlider([DataSourceRequest] DataSourceRequest request, Sliderclass sdr)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Sliders.Add(new Slider()
                    {
                        SlideTitle    = sdr.SlideTitle,
                        SlideImage    = sdr.SlideImage,
                        SlideDesc     = sdr.SlideDesc,
                        SlideIsActive = sdr.SlideIsActive
                    });
                    db.SaveChanges();
                    //return Json(sdr.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
                    return(Json(new[] { sdr }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
                    //return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult());
                }

                else
                {
                    var response = (from u in db.Sliders
                                    orderby u.SlideID descending
                                    select new Sliderclass
                    {
                        SlideID = u.SlideID,
                        SlideTitle = u.SlideTitle,
                    }).ToList();
                    //Apply paging.
                    if (request.Page > 0)
                    {
                        response = response.Skip((request.Page - 1) * request.PageSize).ToList();
                    }
                    response = response.Take(request.PageSize).ToList();

                    return(Json(response.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }
Пример #2
0
        // DELETE: Slider

        public ActionResult DeleteSlider([DataSourceRequest] DataSourceRequest request, Sliderclass sdr)
        {
            try
            {
                var employee = db.Sliders.Find(sdr.SlideID);
                if (employee == null)
                {
                    return(Json("اسلایدر پیدا نشد"));
                }

                db.Sliders.Remove(employee);
                db.SaveChanges();

                //return all data
                var response = (from u in db.Sliders
                                orderby u.SlideID descending
                                select new Sliderclass
                {
                    SlideID = u.SlideID,
                    SlideTitle = u.SlideTitle,
                }).ToList();
                //Apply paging.
                if (request.Page > 0)
                {
                    response = response.Skip((request.Page - 1) * request.PageSize).ToList();
                }
                response = response.Take(request.PageSize).ToList();

                return(Json(response.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }
Пример #3
0
        // UPDATE: Slider

        public ActionResult UpdateSlider([DataSourceRequest] DataSourceRequest request, Sliderclass sdr)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Slider slider = db.Sliders.Find(sdr.SlideID);
                    if (slider != null)
                    {
                        slider.SlideTitle      = sdr.SlideTitle;
                        slider.SlideDesc       = sdr.SlideDesc;
                        slider.SlideImage      = sdr.SlideImage;
                        slider.SlideIsActive   = sdr.SlideIsActive;
                        db.Entry(slider).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    return(Json(new[] { sdr }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var response = (from u in db.Sliders
                                    orderby u.SlideID descending
                                    select new Sliderclass
                    {
                        SlideID = u.SlideID,
                        SlideTitle = u.SlideTitle,
                        SlideImage = u.SlideImage,
                        SlideDesc = u.SlideDesc,
                        SlideIsActive = u.SlideIsActive
                    }).ToList();
                    //Apply paging.
                    if (request.Page > 0)
                    {
                        response = response.Skip((request.Page - 1) * request.PageSize).ToList();
                    }
                    response = response.Take(request.PageSize).ToList();

                    return(Json(response.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }