Beispiel #1
0
        public ActionResult Delete(int Id)
        {
            try
            {
                FeedBusinessLayer _feedBusLayer = new FeedBusinessLayer();
                string            fileName      = _feedBusLayer.DeleteImage(Id);
                var path = Path.Combine(Server.MapPath("~/img"), fileName);


                if ((System.IO.File.Exists(path)))
                {
                    System.IO.File.Delete(path);
                }


                _feedBusLayer.DeleteFeed(Id);
                return(RedirectToAction("ManageFeed", "Home"));
            }

            catch (Exception ex)
            {
                TempData["AlertMessage"] = "Error";
                string Module_name             = "ManageFeed";
                string Action                  = "ManageFeed_Delete";
                ErrorExceptionHandler _handler = new ErrorExceptionHandler();
                _handler.ReportError(Module_name, ex.Message, Action);
                return(RedirectToAction("index", "Exception"));
            }
        }
Beispiel #2
0
        public ActionResult ManageFeed(string search, int?page, int?categoryId)
        {
            try
            {
                //CategoryBusinessLayer CatBussLayer = new CategoryBusinessLayer();
                //ViewBag.Categories = new SelectList(CatBussLayer.Get_Category, "Category_Id", "Category_Name");

                ViewBag.SelectedItem = categoryId;
                CategoryBusinessLayer CatBussLayer = new CategoryBusinessLayer();
                ViewBag.Categories = new SelectList(CatBussLayer.Get_Category(), "Category_Id", "Category_Name", "2");

                //FeedBusinessLayer feedBusLayer = new FeedBusinessLayer();
                //List<Feed> _feeds = feedBusLayer.GetEditFeeds.ToList();

                //return View(_feeds.ToList());

                if (categoryId != null)
                {
                    if (categoryId == 1)
                    {
                        FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                        List <Feed>       feeds        = FeedBusLayer.GetEditFeeds.ToList();
                        return(View(feeds.ToList().ToPagedList(page ?? 1, 8)));
                    }
                    else
                    {
                        FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                        List <Feed>       feeds        = FeedBusLayer.GetEditFeeds.ToList();
                        return(View(feeds.Where(x => x.CategoryID == categoryId).ToList().ToPagedList(page ?? 1, 15)));
                    }
                }

                else if (search == null)
                {
                    FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                    List <Feed>       feeds        = FeedBusLayer.GetEditFeeds.ToList();
                    return(View(feeds.ToList().ToPagedList(page ?? 1, 8)));
                }

                else
                {
                    FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                    List <Feed>       feeds        = FeedBusLayer.GetEditFeeds.ToList();
                    //return View(feeds.Where(x => x.Title.StartsWith(search)).ToList().ToPagedList(page ??5,1));
                    return(View(feeds.Where(x => x.Title.ToLowerInvariant().Contains(search) || search == null).ToList().ToPagedList(page ?? 1, 15)));
                }
            }

            catch (Exception ex)
            {
                TempData["AlertMessage"] = "Error";
                string Module_name             = "ManageFeed";
                string Action                  = "ManageFeed_GetAllFeeds_index";
                ErrorExceptionHandler _handler = new ErrorExceptionHandler();
                _handler.ReportError(Module_name, ex.Message, Action);
                return(RedirectToAction("index", "Exception"));
            }
        }
Beispiel #3
0
        public string GetFeed(int pageNumber, int pageSize)
        {
            string ConnectionName   = "GS_Connect_online";
            string connectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString;

            List <Feed>       Feeds        = new List <Feed>();
            FeedBusinessLayer feedBusLayer = new FeedBusinessLayer();

            Feeds = feedBusLayer.Feeds.ToList();
            JavaScriptSerializer Js = new JavaScriptSerializer();

            return(Js.Serialize(Feeds));
        }
Beispiel #4
0
        public ActionResult Index(string search, int?page, int?categoryId)
        {
            try
            {
                ViewBag.SelectedItem = categoryId;
                CategoryBusinessLayer CatBussLayer = new CategoryBusinessLayer();
                ViewBag.Categories = new SelectList(CatBussLayer.Get_Category(), "Category_Id", "Category_Name", "2");


                if (categoryId != null)
                {
                    if (categoryId == 1)
                    {
                        FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                        List <Feed>       feeds        = FeedBusLayer.Feeds.ToList();
                        return(View(feeds.ToList().ToPagedList(page ?? 1, 15)));
                    }
                    else
                    {
                        FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                        List <Feed>       feeds        = FeedBusLayer.Feeds.ToList();
                        return(View(feeds.Where(x => x.CategoryID == categoryId).ToList().ToPagedList(page ?? 1, 15)));
                    }
                }

                else if (search == null)
                {
                    FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                    List <Feed>       feeds        = FeedBusLayer.Feeds.ToList();
                    return(View(feeds.ToList().ToPagedList(page ?? 1, 15)));
                }

                else
                {
                    FeedBusinessLayer FeedBusLayer = new FeedBusinessLayer();
                    List <Feed>       feeds        = FeedBusLayer.Feeds.ToList();
                    //return View(feeds.Where(x => x.Title.StartsWith(search)).ToList().ToPagedList(page ??5,1));
                    return(View(feeds.Where(x => x.Title.ToLowerInvariant().Contains(search.ToLower()) || search == null).ToList().ToPagedList(page ?? 1, 15)));
                }
            }


            catch (Exception ex)
            {
                string Module_name             = "Home_index";
                string Action                  = "Read all post";
                ErrorExceptionHandler _handler = new ErrorExceptionHandler();
                _handler.ReportError(Module_name, ex.Message, Action);
                return(RedirectToAction("index", "Exception"));
            }
        }
Beispiel #5
0
        public ActionResult Save()
        {
            Feed feed_cs = new Feed();

            TryUpdateModel(feed_cs);

            //feed_cs.CategoryID = 1;   //We are manually setting Cate ID ,hidden in html

            //if (ModelState.IsValid)
            try
            {
                if (feed_cs.File != null)
                {
                    if (feed_cs.File.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(feed_cs.File.FileName);

                        var path = Path.Combine(Server.MapPath("~/img"), fileName);
                        feed_cs.File.SaveAs(path);
                        feed_cs.image = fileName;
                    }
                    else
                    {
                        feed_cs.image = "NIL";
                    }
                }
                else
                {
                    feed_cs.image = "NIL";
                }


                FeedBusinessLayer feedBusLayer = new FeedBusinessLayer();
                feedBusLayer.AddFeed(feed_cs);



                TempData["AlertMessage"] = "Hai this is working";
                return(RedirectToAction("create"));
            }
            catch (Exception ex)
            {
                TempData["AlertMessage"] = "Error";
                string Module_name             = "Home_Create";
                string Action                  = "Create new post";
                ErrorExceptionHandler _handler = new ErrorExceptionHandler();
                _handler.ReportError(Module_name, ex.Message, Action);
                return(RedirectToAction("index", "Exception"));
            }
        }
Beispiel #6
0
        public ActionResult Update(Feed _Feed)
        {
            FeedBusinessLayer _feedBusLayer = new FeedBusinessLayer();

            TryUpdateModel(_Feed);
            // _Feed.CategoryID = 1;//we are maually setting CategoryID
            //if (ModelState.IsValid)
            try
            {
                if (_Feed.File != null)
                {
                    if (_Feed.File.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(_Feed.File.FileName);

                        var path = Path.Combine(Server.MapPath("~/img"), fileName);
                        _Feed.File.SaveAs(path);
                        _Feed.image = fileName;
                    }
                }

                else if (_Feed.image == null)
                {
                    _Feed.image = "NIL";
                }

                _feedBusLayer.UpdateFeed(_Feed);
                TempData["AlertMessage"] = "Hai this is working";
                return(RedirectToAction("ManageFeed", "Home"));
            }

            catch (Exception ex)
            {
                TempData["AlertMessage"] = "Error";
                string Module_name             = "ManageFeed_Update";
                string Action                  = "Save";
                ErrorExceptionHandler _handler = new ErrorExceptionHandler();
                _handler.ReportError(Module_name, ex.Message, Action);
                return(RedirectToAction("index", "Exception"));
            }



            //return RedirectToAction("ManageFeed", "Home");
        }
Beispiel #7
0
        [HttpGet]//when press edit button
        public ActionResult Edit(int Id)
        {
            try
            {
                FeedBusinessLayer _feedBusLayer = new FeedBusinessLayer();
                Feed _feed = _feedBusLayer.GetEditFeeds.Single(fd => fd.ID == Id);
                return(View(_feed));
            }



            catch (Exception ex)
            {
                TempData["AlertMessage"] = "Error";
                string Module_name             = "ManageFeed_Edit";
                string Action                  = "Get";
                ErrorExceptionHandler _handler = new ErrorExceptionHandler();
                _handler.ReportError(Module_name, ex.Message, Action);
                return(RedirectToAction("index", "Exception"));
            }
        }