Ejemplo n.º 1
0
        public ActionResult NewsOperation(string type,string content,string newsTitle,int? newsID)
        {
            if (type == "addNews")
            {
                if (isLogin("NewsEditor?type=addNews"))
                {
                    Models.BookShopEntities4 db = new Models.BookShopEntities4();
                            Models.newsInfo ni = new Models.newsInfo()
                            {
                                submitId = Session["adminLogin"].ToString(),
                                submitor = Session["adminNick"].ToString(),
                                newsContent = content,
                                newsTitle = newsTitle,
                                sumitTime = DateTime.Now
                            };
                            db.newsInfo.Add(ni);
                            db.SaveChanges();
                            Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('新增动态成功,页面跳转到动态管理',function (){location='/Manage/NewsAdmin'});}</script>");
                    return View();
                }
                else
                {
                    return RedirectToAction("Error", "Manage");
                }

            }
            else
            {
                if (isLogin("NewsAdmin"))
                {
                    Models.BookShopEntities4 db = new Models.BookShopEntities4();
                    switch (type)
                    {
                        case "deleteNews":
                            try
                            {
                                var dele = db.newsInfo.Where(a => a.newsId == newsID).FirstOrDefault();
                                db.newsInfo.Remove(dele);
                                db.SaveChanges();
                                Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('删除动态成功',function (){location='/Manage/NewsAdmin'});}</script>");
                            }
                            catch
                            {

                            }
                            break;
                        case "updateNews":
                            var up = db.newsInfo.Where(a => a.newsId == newsID).FirstOrDefault();
                            up.newsTitle = newsTitle;
                            up.newsContent = content;
                            db.SaveChanges();
                            Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('动态修改成功',function (){location='/Manage/NewsAdmin'});}</script>");
                            break;
                    }
                    return View();
                }
                else
                {
                    return RedirectToAction("Error", "Manage");
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult NewsOperation(string type, string content, string newsTitle, int?newsID)
        {
            if (type == "addNews")
            {
                if (isLogin("NewsEditor?type=addNews"))
                {
                    Models.BookShopEntities4 db = new Models.BookShopEntities4();
                    Models.newsInfo          ni = new Models.newsInfo()
                    {
                        submitId    = Session["adminLogin"].ToString(),
                        submitor    = Session["adminNick"].ToString(),
                        newsContent = content,
                        newsTitle   = newsTitle,
                        sumitTime   = DateTime.Now
                    };
                    db.newsInfo.Add(ni);
                    db.SaveChanges();
                    Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('新增动态成功,页面跳转到动态管理',function (){location='/Manage/NewsAdmin'});}</script>");
                    return(View());
                }
                else
                {
                    return(RedirectToAction("Error", "Manage"));
                }
            }
            else
            {
                if (isLogin("NewsAdmin"))
                {
                    Models.BookShopEntities4 db = new Models.BookShopEntities4();
                    switch (type)
                    {
                    case "deleteNews":
                        try
                        {
                            var dele = db.newsInfo.Where(a => a.newsId == newsID).FirstOrDefault();
                            db.newsInfo.Remove(dele);
                            db.SaveChanges();
                            Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('删除动态成功',function (){location='/Manage/NewsAdmin'});}</script>");
                        }
                        catch
                        {
                        }
                        break;

                    case "updateNews":
                        var up = db.newsInfo.Where(a => a.newsId == newsID).FirstOrDefault();
                        up.newsTitle   = newsTitle;
                        up.newsContent = content;
                        db.SaveChanges();
                        Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('动态修改成功',function (){location='/Manage/NewsAdmin'});}</script>");
                        break;
                    }
                    return(View());
                }
                else
                {
                    return(RedirectToAction("Error", "Manage"));
                }
            }
        }