Example #1
0
 public JsonResult GetbyID(int ID)
 {
     try
     {
         List <DLNews> lst   = bal.LoadData();
         DLNews        admin = new DLNews();
         foreach (var l in lst)
         {
             if (l.NewsId == ID)
             {
                 admin = l;
                 break;
             }
         }
         return(Json(admin, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
        public int Register(DLNews news, string action)
        {
            int i = 0;

            try
            {
                SqlCommand cmd = new SqlCommand("StoredProcNews", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@NewsId", Convert.ToInt32(news.NewsId));
                cmd.Parameters.AddWithValue("@Title", news.Title.ToString());

                cmd.Parameters.AddWithValue("@Description", news.Description.ToString());
                cmd.Parameters.AddWithValue("@image", news.Image.ToString());
                cmd.Parameters.AddWithValue("@isactive", 1);

                cmd.Parameters.AddWithValue("@Action", action);

                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                i = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
            }
            return(i);
        }
Example #3
0
        public ActionResult News(DLNews news, string save, List <HttpPostedFileBase> postedFiles)
        {
            try
            {
                if (news.NewsId == 0)
                {
                    if (ModelState.IsValid)
                    {
                        return(View(news));
                    }
                }
                else
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(news));
                    }
                }
                int action;

                if (!String.IsNullOrEmpty(save))
                {
                    action = bal.Register(news, "Insert");
                }
                else
                {
                    action = bal.Register(news, "Update");
                }
                if (action > 0)
                {
                    int NewsId = 0;
                    if (!String.IsNullOrEmpty(save))
                    {
                        List <DLNews> list = bal.LoadData();
                        DLNews        p    = new DLNews();
                        foreach (var l in list)
                        {
                            p = l;
                        }
                        NewsId = p.NewsId;
                    }
                    else
                    {
                        NewsId = news.NewsId;
                    }

                    foreach (HttpPostedFileBase file in postedFiles)
                    {
                        if (file != null)
                        {
                            file.SaveAs(Server.MapPath("~/Content/Images/News/" + file.FileName));
                            bool registerImage = bal.RegisterImage(NewsId, file.FileName);
                        }
                    }
                    TempData["Error"] = "Data Added Succesfully";
                }
                else
                {
                    TempData["Error"] = "Something Happens Wrong !!!!";
                }
                return(Redirect("/News/News"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }