예제 #1
0
        public long UpdateNews(TblNews entity)
        {
            var news = da.TblNews.Find(entity.ID);

            if (news != null)
            {
                try
                {
                    // set data
                    news.Name         = entity.Name;
                    news.MetaTitle    = entity.MetaTitle;
                    news.Content      = entity.Content;
                    news.Image        = entity.Image;
                    news.Status       = entity.Status;
                    news.DESCRIPTION  = entity.DESCRIPTION;
                    news.del_flg      = Constant.DeleteFlag.NON_DELETE;
                    news.ModifiedDate = DateTime.Now;
                    news.ModifiedBy   = CmnEntityModel.ID;

                    da.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(0);
            }

            return(entity.ID);
        }
예제 #2
0
        public async Task <string> Post(TblNews tblNews)
        {
            try
            {
                tblNews.UrlFriendly     = CommonUtil.UrlFriendly(tblNews.TitleNews);
                tblNews.DescriptionNews = CommonUtil.StripHTML(tblNews.Content);
                if (tblNews.DescriptionNews != null && tblNews.DescriptionNews.Length > 150)
                {
                    tblNews.DescriptionNews = tblNews.DescriptionNews.Substring(0, 150) + ComConst.READ_MORE;
                }

                var filePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot/images", tblNews.UrlFriendly + ".jpg");
                await LoadImageFromUrl(filePath, tblNews.UrlImg);

                tblNews.UrlImg   = ComConst.URL + "/images/" + tblNews.UrlFriendly + ".jpg";
                tblNews.DateNews = DateTime.Now;
                _context.Add(tblNews);
                _context.SaveChanges();

                LIST_CATEGORY = _context.TblCategory.ToList();
                LIST_NEWS     = _context.TblNews.ToList();
                return("thành công");
            } catch (Exception ex)
            {
                return(ex.Message);
            }
        }
예제 #3
0
        public ActionResult DeleteNews(int id)
        {
            if (ClsCheckRole.CheckQuyen(4, 3, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
            {
                TblNews TblNews = db.TblNews.Find(id);
                clsSitemap.DeteleSitemap(id.ToString(), "News");
                var result  = string.Empty;
                int ord     = int.Parse(TblNews.Ord.ToString());
                int idCate  = int.Parse(TblNews.IdCate.ToString());
                var kiemtra = db.TblNews.Where(p => p.Ord > ord && p.IdCate == idCate).ToList();
                if (kiemtra.Count > 0)
                {
                    var ListNews = db.TblNews.Where(p => p.Ord > ord && p.IdCate == idCate).ToList();
                    for (int i = 0; i < ListNews.Count; i++)
                    {
                        int idp        = int.Parse(ListNews[i].Id.ToString());
                        var NewsUpdate = db.TblNews.Find(idp);
                        NewsUpdate.Ord = NewsUpdate.Ord - 1;
                        db.SaveChanges();
                    }
                }
                db.TblNews.Remove(TblNews);
                db.SaveChanges();
                result = "Bạn đã xóa thành công.";
                return(Json(new { result = result }));
            }
            else
            {
                var result = string.Empty;

                result = "Bạn không có quyền thay đổi tính năng này !.";
                return(Json(new { result = result }));
            }
        }
예제 #4
0
        // GET: ManageNews
        #region REGISTER/ UPDATE
        public ActionResult NewsEdit(long newsId = 0)
        {
            CmnEntityModel currentUser = Session["CmnEntityModel"] as CmnEntityModel;

            if (currentUser == null || currentUser.IsAdmin == false)
            {
                return(RedirectToAction("Login", "Login"));
            }

            TblNews       model      = new TblNews();
            CommonService comService = new CommonService();
            ManageNewsDa  dataAccess = new ManageNewsDa();

            model.Status = Constant.Status.ACTIVE;

            if (newsId > 0)
            {
                TblNews infor = new TblNews();
                infor         = dataAccess.getInfoNews(newsId);
                model         = infor != null ? infor : model;
                model.Content = HttpUtility.HtmlDecode(model.Content);
            }

            return(View(model));
        }
예제 #5
0
        public long UpdateNews(TblNews model)
        {
            long res = 0;
            // Declare new DataAccess object
            ManageNewsDa dataAccess = new ManageNewsDa();

            using (var transaction = new TransactionScope())
            {
                try
                {
                    model.MetaTitle = model.Name.Contains("/") ? model.Name.Replace("/", "") : model.Name;
                    model.MetaTitle = UtilityServices.UtilityServices.ConvertToUnsign(model.MetaTitle);
                    res             = dataAccess.UpdateNews(model);

                    if (res <= 0)
                    {
                        transaction.Dispose();
                    }
                    transaction.Complete();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }
                finally
                {
                    transaction.Dispose();
                }
            }
            return(res);
        }
예제 #6
0
        public async Task <TblNews> AddNews(TblNews news)
        {
            HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync("api/NewsCore/AddNews", news);

            TblNews ans = await httpResponseMessage.Content.ReadAsAsync <TblNews>();

            return(ans);
        }
예제 #7
0
        public async Task <TblNews> DeleteNews(int id)
        {
            HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync($"api/DeleteNews/DeleteNews?id={id}", id);

            TblNews ans = await httpResponseMessage.Content.ReadAsAsync <TblNews>();

            return(ans);
        }
예제 #8
0
        public IActionResult News(string urlFriendly)
        {
            // Get data header page
            TblNews tblNews = LIST_NEWS.Where(o => o.UrlFriendly == urlFriendly).First();

            CreateHeader(tblNews.Category.CategoryId, tblNews.TitleNews);
            mymodel.News = tblNews;
            return(View(mymodel));
        }
        public DtoTblNews(TblNews news, HttpStatusCode statusEffect)
        {
            id          = news.id;
            Title       = news.Title;
            MainData    = news.MainData;
            MainDataRtf = news.MainDataRtf;

            StatusEffect = statusEffect;
        }
예제 #10
0
        public ActionResult Edit(int?id)
        {
            if ((Request.Cookies["Username"] == null))
            {
                return(RedirectToAction("LoginIndex", "Login"));
            }
            if (ClsCheckRole.CheckQuyen(5, 2, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
            {
                Session["id"] = id.ToString();
                Int32   ids     = Int32.Parse(id.ToString());
                TblNews TblNews = db.TblNews.Find(ids);

                if (TblNews == null)
                {
                    return(HttpNotFound());
                }
                var menuModel = db.TblGroupNews.Where(m => m.ParentId == null).OrderBy(m => m.Id).ToList();
                carlist.Clear();
                string strReturns = "---";
                foreach (var item in menuModel)
                {
                    carlist.Add(new SelectListItem {
                        Text = item.Name, Value = item.Id.ToString()
                    });
                    StringClass.DropDownListNews(item.Id, carlist, strReturns);
                    strReturns = "---";
                }
                int idGroups = 0;
                if (TblNews.IdCate != null)
                {
                    idGroups = int.Parse(TblNews.IdCate.ToString());
                }
                ViewBag.drMenu = new SelectList(carlist, "Value", "Text", idGroups);


                var Manufacture = db.TblManufactures.Where(m => m.Active == true).OrderBy(m => m.Ord).ToList();
                var listIdManu  = db.TblConnectManuToNews.Where(p => p.IdNews == id).Select(p => p.IdManu).ToList();
                var lstmanu     = new List <SelectListItem>();

                foreach (var item in Manufacture)
                {
                    lstmanu.Add(new SelectListItem {
                        Text = item.Name, Value = item.Id.ToString()
                    });
                }
                ViewBag.mutilManu = new MultiSelectList(lstmanu, "Value", "Text", listIdManu);
                return(View(TblNews));
            }
            else
            {
                return(Redirect("/Users/Erro"));
            }
        }
예제 #11
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string  msg = "News detail has been added!";
                TblNews obj = new TblNews();
                obj.IsNew = true;

                if (Session["NewsID"] != null)
                {
                    obj.IsNew = false;
                    obj       = new TblNews(Session["NewsID"]);
                    msg       = "News detail has been updated!";
                }

                string PostedFile = null;

                if (FileUpload1.HasFile)
                {
                    PostedFile = FileUpload1.PostedFile.FileName;

                    if (File.Exists(Server.MapPath("~/Admin/assets/CustomImages/NewsImages/" + PostedFile)))
                    {
                        int c = 1;
                        while (File.Exists(Server.MapPath("~/Admin/assets/CustomImages/NewsImages/" + PostedFile)))
                        {
                            PostedFile = c.ToString() + FileUpload1.PostedFile.FileName;
                            c++;
                        }
                    }

                    FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Admin/assets/CustomImages/NewsImages/" + PostedFile));
                    obj.Image = PostedFile;
                }



                obj.Heading     = txtHeading.Text;
                obj.Description = txtDescription.Text;
                obj.PostedDate  = helper.getDateTime();
                obj.ExpiryDate  = DateTime.Now.AddDays(30);
                obj.IsActive    = true;
                obj.Save();
                lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, msg, "alert alert-success alert-icon alert-dismissible", icon, "icon mdi mdi-check");
                helper.ClearInputs(Page.Controls);
                Session["NewsID"] = null;
                reqFile.Enabled   = true;
            }
            catch (Exception ex)
            {
                lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, ex.ToString(), "alert alert-danger alert-icon alert-dismissible", icon, "icon mdi mdi-close-circle-o");
            }
        }
예제 #12
0
        public long InsertNews(TblNews entity)
        {
            entity.del_flg      = Constant.DeleteFlag.NON_DELETE;
            entity.CreatedDate  = DateTime.Now;
            entity.CreatedBy    = CmnEntityModel.ID;
            entity.ModifiedDate = DateTime.Now;
            entity.ModifiedBy   = CmnEntityModel.ID;

            da.TblNews.Add(entity);
            da.SaveChanges();
            return(entity.ID);
        }
예제 #13
0
        public async Task <bool> UpdateNews(TblNews news, int logId)
        {
            List <object> newsAndLogId = new List <object>();

            newsAndLogId.Add(news);
            newsAndLogId.Add(logId);
            HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync("api/NewsCore/UpdateNews", newsAndLogId);

            bool ans = await httpResponseMessage.Content.ReadAsAsync <bool>();

            return(ans);
        }
예제 #14
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Session["NewsID"] != null)
         {
             TblNews obj = new TblNews(Session["NewsID"]);
             txtHeading.Text     = obj.Heading;
             txtDescription.Text = obj.Description;
             reqFile.Enabled     = false;
         }
     }
 }
예제 #15
0
        public IHttpActionResult AddNews(TblNews news)
        {
            var task = Task.Run(() => new NewsService().AddNews(news));

            if (task.Wait(TimeSpan.FromSeconds(10)))
            {
                if (task.Result.id != -1)
                {
                    return(Ok(new DtoTblNews(task.Result, HttpStatusCode.OK)));
                }
                else
                {
                    return(Conflict());
                }
            }
            return(StatusCode(HttpStatusCode.RequestTimeout));
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton NewsID = (LinkButton)sender;

                TblNews obj      = new TblNews(NewsID.CommandArgument);
                var     filePath = Server.MapPath("~/Admin/assets/CustomImages/NewsImages/" + obj.Image);
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                TblNews.Delete(NewsID.CommandArgument);
                lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, "News detail has been deleted!", "alert alert-danger alert-icon alert-dismissible", icon, "icon mdi mdi-check");
                BindNews();
            }
            catch { }
        }
예제 #17
0
        public IHttpActionResult UpdateNews(List <object> newsLogId)
        {
            TblNews news  = JsonConvert.DeserializeObject <TblNews>(newsLogId[0].ToString());
            int     logId = JsonConvert.DeserializeObject <int>(newsLogId[1].ToString());
            var     task  = Task.Run(() => new NewsService().UpdateNews(news, logId));

            if (task.Wait(TimeSpan.FromSeconds(10)))
            {
                if (task.Result)
                {
                    return(Ok(true));
                }
                else
                {
                    return(Conflict());
                }
            }
            return(StatusCode(HttpStatusCode.RequestTimeout));
        }
예제 #18
0
        public ActionResult NewsDetail(long newsId = 0)
        {
            TblNews      model      = new TblNews();
            ManageNewsDa dataAccess = new ManageNewsDa();
            NewsService  service    = new NewsService();

            model.Status = Constant.Status.ACTIVE;

            if (newsId > 0)
            {
                TblNews infor = new TblNews();
                infor                = dataAccess.getInfoNews(newsId);
                model                = infor != null ? infor : model;
                model.Content        = HttpUtility.HtmlDecode(model.Content);
                @ViewBag.listNewMore = service.GetListNews(10);
            }

            return(View(model));
        }
예제 #19
0
        public ActionResult Edit(TblNews model)
        {
            try
            {
                using (NewsService service = new NewsService())
                {
                    if (ModelState.IsValid)
                    {
                        bool isNew = false;

                        if (model.ID == 0)
                        {
                            isNew = true;
                            service.InsertNews(model);
                            JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet);
                            return(result);
                        }
                        else
                        {
                            isNew = false;
                            service.UpdateNews(model);
                            JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet);
                            return(result);
                        }
                    }
                    else
                    {
                        var ErrorMessages = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                    }

                    return(new EmptyResult());
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                System.Web.HttpContext.Current.Session["ERROR"] = ex;
                return(new EmptyResult());
            }
        }
 public TblNews AddNews(TblNews news)
 {
     return(new NewsRepo().AddNews(news));
 }
 public bool UpdateNews(TblNews news, int logId)
 {
     return(new NewsRepo().UpdateNews(news, logId));
 }
예제 #22
0
        public TblNews getInfoNews(long Id)
        {
            TblNews product = da.TblNews.Where(s => s.ID == Id).SingleOrDefault();

            return(product);
        }
예제 #23
0
        public ActionResult Edit(TblNews TblNews, FormCollection collection, int?id, int[] mutilManu)
        {
            if (ModelState.IsValid)
            {
                if (collection["drMenu"] != "" || collection["drMenu"] != null)
                {
                    string IdUser = Request.Cookies["Username"].Values["UserID"];
                    TblNews.IdUser = int.Parse(IdUser);
                    bool URL = (collection["URL"] == "false") ? false : true;
                    if (URL == true)
                    {
                        TblNews.Tag = StringClass.NameToTag(TblNews.Name);
                    }
                    else
                    {
                        TblNews.Tag = collection["NameURL"];
                    }
                    clsSitemap.CreateSitemap(TblNews.Tag, id.ToString(), "Newsad");
                    TblNews.IdCate          = int.Parse(collection["drMenu"]);
                    TblNews.DateCreate      = DateTime.Now;
                    db.Entry(TblNews).State = EntityState.Modified;
                    db.SaveChanges();

                    if (URL == true)
                    {
                        TblNews.Tag = StringClass.NameToTag(TblNews.Name);
                        clsSitemap.UpdateSitemap(StringClass.NameToTag(TblNews.Name) + ".htm", id.ToString(), "News");
                    }
                    else
                    {
                        TblNews.Tag = collection["NameURL"];
                        clsSitemap.UpdateSitemap(StringClass.NameToTag(TblNews.Name) + ".htm", id.ToString(), "News");
                    }
                    int Ord     = int.Parse(TblNews.Ord.ToString());
                    int idCate  = int.Parse(collection["drMenu"]);
                    var Kiemtra = db.TblNews.Where(p => p.Ord == Ord && p.IdCate == idCate && p.Id != id).ToList();
                    if (Kiemtra.Count > 0)
                    {
                        var ListNewss = db.TblNews.Where(p => p.Ord >= Ord && p.IdCate == idCate).ToList();
                        for (int i = 0; i < ListNewss.Count; i++)
                        {
                            int idp       = int.Parse(ListNewss[i].Id.ToString());
                            var NewUpdate = db.TblNews.Find(idp);
                            NewUpdate.Ord = NewUpdate.Ord + 1;
                            db.SaveChanges();
                        }
                    }
                    db.SaveChanges();

                    var listNewsTag = db.TblNewsTag.Where(p => p.Idn == id).ToList();
                    for (int i = 0; i < listNewsTag.Count; i++)
                    {
                        int        ids         = listNewsTag[i].Id;
                        TblNewsTag TblNewstags = db.TblNewsTag.Find(ids);
                        db.TblNewsTag.Remove(TblNewstags);
                        db.SaveChanges();
                    }
                    string   nkeyword    = collection["Tabs"];
                    string[] mangKeyword = nkeyword.Split(',');
                    for (int i = 0; i < mangKeyword.Length; i++)
                    {
                        if (mangKeyword[i] != null && mangKeyword[i] != "")
                        {
                            TblNewsTag TblNewstags = new TblNewsTag();
                            TblNewstags.Idn  = id;
                            TblNewstags.Name = mangKeyword[i];
                            TblNewstags.Tag  = StringClass.NameToTag(mangKeyword[i]);
                            db.TblNewsTag.Add(TblNewstags);
                            db.SaveChanges();
                        }
                    }
                    var listIdManu = db.TblConnectManuToNews.Where(p => p.IdNews == id).ToList();
                    for (int i = 0; i < listIdManu.Count; i++)
                    {
                        db.TblConnectManuToNews.Remove(listIdManu[i]);
                        db.SaveChanges();
                    }
                    if (mutilManu != null)
                    {
                        foreach (var idMenu in mutilManu)
                        {
                            TblConnectManuToNews connectimage = new TblConnectManuToNews();
                            connectimage.IdManu = idMenu;
                            connectimage.IdNews = id;
                            db.TblConnectManuToNews.Add(connectimage);
                            db.SaveChanges();
                        }
                    }
                }
                if (collection["btnSave"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã sửa tin thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

                    return(Redirect("/Newsad/Index?idCate=" + int.Parse(collection["drMenu"])));
                }
                if (collection["btnSaveCreate"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã thêm tin thành công, mời bạn thêm tin mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                    return(Redirect("/Newsad/Create?id=" + +int.Parse(collection["drMenu"]) + ""));
                }
                #region [Updatehistory]
                #endregion
            }
            return(View(TblNews));
        }
 public TblNews AddNews(TblNews news)
 {
     return((TblNews) new MainProvider().Add(news));
 }
예제 #25
0
        public ActionResult Create(TblNews TblNews, FormCollection Collection, string id, int[] mutilManu)
        {
            if ((Request.Cookies["Username"] == null))
            {
                return(RedirectToAction("LoginIndex", "Login"));
            }


            string nidCate = Collection["drMenu"];

            if (nidCate != "")
            {
                TblNews.IdCate = int.Parse(nidCate);
                int idcate = int.Parse(nidCate);
                TblNews.DateCreate = DateTime.Now;
                TblNews.Tag        = StringClass.NameToTag(TblNews.Name);
                TblNews.DateCreate = DateTime.Now;
                TblNews.Visit      = 0;
                string IdUser = Request.Cookies["Username"].Values["UserID"];
                TblNews.IdUser = int.Parse(IdUser);
                db.TblNews.Add(TblNews);
                db.SaveChanges(); var ListNews = db.TblNews.OrderByDescending(p => p.Id).Take(1).ToList();

                int      IdNews      = int.Parse(ListNews[0].Id.ToString());
                string   nkeyword    = TblNews.Tabs;
                string[] mangKeyword = nkeyword.Split(',');
                for (int i = 0; i < mangKeyword.Length; i++)
                {
                    if (mangKeyword[i] != null && mangKeyword[i] != "")
                    {
                        TblNewsTag TblNewstag = new TblNewsTag();
                        TblNewstag.Idn  = IdNews;
                        TblNewstag.Name = mangKeyword[i];
                        TblNewstag.Tag  = StringClass.NameToTag(mangKeyword[i]);
                        db.TblNewsTag.Add(TblNewstag);
                        db.SaveChanges();
                    }
                }
                var listprro = db.TblNews.OrderByDescending(p => p.Id).Take(1).ToList();
                clsSitemap.CreateSitemap(TblNews.Tag + ".htm", listprro[0].Id.ToString(), "News");
                #region [Updatehistory]
                #endregion

                if (mutilManu != null)
                {
                    foreach (var idMenu in mutilManu)
                    {
                        TblConnectManuToNews conntectNews = new TblConnectManuToNews();
                        conntectNews.IdManu = idMenu;
                        conntectNews.IdNews = IdNews;
                        db.TblConnectManuToNews.Add(conntectNews);
                        db.SaveChanges();
                    }
                }
                if (Collection["btnSave"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã thêm tinthành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                    return(Redirect("/Newsad/index?idCate=" + nidCate + ""));
                }
                if (Collection["btnSaveCreate"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã thêm tin  thành công, mời bạn thêm tin mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                    return(Redirect("/Newsad/Create?id=" + nidCate + ""));
                }
            }
            return(View());
        }
예제 #26
0
        public ActionResult Index(int?page, string text, string idCate, string pageSizes, FormCollection collection)
        {
            if ((Request.Cookies["Username"] == null))
            {
                return(RedirectToAction("LoginIndex", "Login"));
            }
            if (ClsCheckRole.CheckQuyen(5, 0, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
            {
                #region [Load Menu]

                var    pro       = db.TblGroupNews.OrderByDescending(p => p.Ord).Take(1).ToList();
                var    menuModel = db.TblGroupNews.Where(m => m.ParentId == null).OrderBy(m => m.Id).ToList(); carlist.Clear();
                string strReturn = "---";
                foreach (var item in menuModel)
                {
                    carlist.Add(new SelectListItem {
                        Text = item.Name, Value = item.Id.ToString()
                    });
                    StringClass.DropDownListNews(item.Id, carlist, strReturn);
                    strReturn = "---";
                }
                if (idCate != "")
                {
                    ViewBag.drMenu = new SelectList(carlist, "Value", "Text", idCate);
                    ViewBag.IdCate = idCate;
                    ViewBag.IdMenu = idCate;
                }
                else
                {
                    ViewBag.drMenu = carlist;
                }
                #endregion
                if (Session["Thongbao"] != null && Session["Thongbao"] != "")
                {
                    ViewBag.thongbao    = Session["Thongbao"].ToString();
                    Session["Thongbao"] = "";
                }
                if (collection["btnDelete"] != null)
                {
                    foreach (string key in Request.Form.Keys)
                    {
                        var checkbox = "";
                        if (key.StartsWith("chk_"))
                        {
                            checkbox = Request.Form["" + key];
                            if (checkbox != "false")
                            {
                                if (ClsCheckRole.CheckQuyen(5, 3, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
                                {
                                    int     id      = Convert.ToInt32(key.Remove(0, 4));
                                    TblNews TblNews = db.TblNews.Find(id);
                                    int     ord     = int.Parse(TblNews.Ord.ToString());
                                    int     idCates = int.Parse(TblNews.IdCate.ToString());
                                    var     kiemtra = db.TblNews.Where(p => p.Ord > ord && p.IdCate == idCates).ToList();
                                    if (kiemtra.Count > 0)
                                    {
                                        var ListNews = db.TblNews.Where(p => p.Ord > ord && p.IdCate == idCates).ToList();
                                        for (int i = 0; i < ListNews.Count; i++)
                                        {
                                            int idp        = int.Parse(ListNews[i].Id.ToString());
                                            var NewsUpdate = db.TblNews.Find(idp);
                                            NewsUpdate.Ord = NewsUpdate.Ord - 1;
                                            db.SaveChanges();
                                        }
                                    }
                                    db.TblNews.Remove(TblNews);
                                    db.SaveChanges();
                                    clsSitemap.DeteleSitemap(id.ToString(), "News");
                                }
                                else
                                {
                                    return(Redirect("/Users/Erro"));
                                }
                            }
                        }
                    }
                    //dsd
                }
                return(View());
            }
            else
            {
                return(Redirect("/Users/Erro"));
            }
        }
 public bool UpdateNews(TblNews news, int logId)
 {
     return(new MainProvider().Update(news, logId));
 }
예제 #28
0
        public ActionResult newsDetail(string tag)
        {
            TblNews TblNews = db.TblNews.First(p => p.Tag == tag);
            int     id      = TblNews.Id;

            TblGroupNews groupNews = db.TblGroupNews.First(p => p.Id == TblNews.IdCate.Value);

            ViewBag.menuName    = groupNews.Name;
            ViewBag.tagMenuName = groupNews.Tag;
            var tblconfig = db.TblConfig.FirstOrDefault();

            ViewBag.color = tblconfig.Color;
            if (TblNews.Style == true)
            {
                ViewBag.style  = "width:100% !important; margin:0px";
                ViewBag.style1 = "display:none";
            }
            ViewBag.Title       = "<title>" + TblNews.Title + "</title>";
            ViewBag.Description = "<meta name=\"description\" content=\"" + TblNews.Description + "\"/>";
            ViewBag.Keyword     = "<meta name=\"keywords\" content=\"" + TblNews.Keyword + "\" /> ";
            ViewBag.dcTitle     = "<meta name=\"DC.title\" content=\"" + TblNews.Title + "\" />";
            if (TblNews.Meta != null && TblNews.Meta != "")
            {
                int phut = DateTime.Now.Minute * 2;
                ViewBag.refresh = "<meta http-equiv=\"refresh\" content=\"" + phut + "; url=" + TblNews.Meta + "\">";
            }
            ViewBag.dcDescription = "<meta name=\"DC.description\" content=\"" + TblNews.Description + "\" />";
            string meta = "";

            ViewBag.canonical = "<link rel=\"canonical\" href=\"http://Bontana.vn/tin-tuc/" + StringClass.NameToTag(tag) + "\" />";

            meta        += "<meta itemprop=\"name\" content=\"" + TblNews.Name + "\" />";
            meta        += "<meta itemprop=\"url\" content=\"" + Request.Url.ToString() + "\" />";
            meta        += "<meta itemprop=\"description\" content=\"" + TblNews.Description + "\" />";
            meta        += "<meta itemprop=\"image\" content=\"http://Bontana.vn" + TblNews.Images + "\" />";
            meta        += "<meta property=\"og:title\" content=\"" + TblNews.Title + "\" />";
            meta        += "<meta property=\"og:type\" content=\"product\" />";
            meta        += "<meta property=\"og:url\" content=\"" + Request.Url.ToString() + "\" />";
            meta        += "<meta property=\"og:image\" content=\"http://Bontana.vn" + TblNews.Images + "\" />";
            meta        += "<meta property=\"og:site_name\" content=\"http://Bontana.vn\" />";
            meta        += "<meta property=\"og:description\" content=\"" + TblNews.Description + "\" />";
            meta        += "<meta property=\"fb:admins\" content=\"\" />";
            ViewBag.Meta = meta;
            StringBuilder schame = new StringBuilder();

            schame.Append("<script type=\"application/ld+json\">");
            schame.Append("{");
            schame.Append("\"@context\": \"http://schema.org\",");
            schame.Append("\"@type\": \"NewsArticle\",");
            schame.Append("\"headline\": \"" + TblNews.Description + "\",");
            schame.Append(" \"datePublished\": \"" + TblNews.DateCreate + "\",");
            schame.Append("\"image\": [");
            schame.Append(" \"" + TblNews.Images + "\"");
            schame.Append(" ]");
            schame.Append("}");
            schame.Append("</script> ");
            ViewBag.schame = schame.ToString();
            int IdUser = int.Parse(TblNews.IdUser.ToString());

            ViewBag.user = db.TblUser.First(p => p.Id == IdUser).UserName;
            string tab      = TblNews.Tabs;
            string Tabsnews = "";

            if (tab != null)
            {
                string[] mang = tab.Split(',');
                for (int i = 0; i < mang.Length; i++)
                {
                    Tabsnews += " <a href=\"/TagNews/" + StringClass.NameToTag(mang[i]) + "\" title=\"" + mang[i] + "\">" + mang[i] + "</a>";
                }
                ViewBag.tags = Tabsnews;
            }
            StringBuilder result = new StringBuilder();

            var listnews = db.TblNews.Where(p => p.Active == true && p.Id != id).OrderByDescending(p => p.DateCreate).Take(5).ToList();

            if (listnews.Count > 0)
            {
                for (int j = 0; j < listnews.Count; j++)
                {
                    result.Append(" <li><a href=\"/tin-tuc/" + listnews[j].Tag + "\" title=\"" + listnews[j].Name + "\"><i class=\"fa fa-angle-right\" aria-hidden=\"true\"></i>  " + listnews[j].Name + "</a><span>");
                    result.Append("  <i class=\"fa fa-clock-o\" aria-hidden=\"true\"></i>  Viết ngày : " + listnews[j].DateCreate + "    </span><li>");
                }
            }
            ViewBag.result  = result.ToString();
            ViewBag.favicon = " <link href=\"" + tblconfig.Favicon + "\" rel=\"icon\" type=\"image/x-icon\" />";
            ViewBag.nUrl    = "<ol itemscope itemtype=\"http://schema.org/BreadcrumbList\">   <li itemprop=\"itemListElement\" itemscope  itemtype=\"http://schema.org/ListItem\"> <a itemprop=\"item\" href=\"http://Bontana.vn\">  <span itemprop=\"name\">Trang chủ</span></a> <meta itemprop=\"position\" content=\"1\" />  </li>   ›" + Urlnews(TblNews.IdCate.Value) + "</ol>";
            int visit = int.Parse(TblNews.Visit.ToString());

            if (visit > 0)
            {
                TblNews.Visit = TblNews.Visit + 1;
                db.SaveChanges();
            }
            else
            {
                TblNews.Visit = TblNews.Visit + 1;
                db.SaveChanges();
            }
            return(View(TblNews));
        }