예제 #1
0
        public JsonResult ApprovePost(int?Id)
        {
            try
            {
                using (NewsPortalEntities portalEntities = new NewsPortalEntities())
                {
                    var      currentUser = (ClaimsPrincipal)Thread.CurrentPrincipal;
                    var      UserId      = currentUser.Claims.Where(x => x.Type == ClaimTypes.PrimarySid).Select(c => c.Value).SingleOrDefault();
                    NewsPost newsPost    = portalEntities.NewsPosts.Where(x => x.Id == Id).FirstOrDefault();
                    newsPost.IsReviewed = true;
                    newsPost.ReviewedBy = int.Parse(UserId);;
                    portalEntities.NewsPosts.Attach(newsPost);
                    portalEntities.Entry(newsPost).State = EntityState.Modified;
                    portalEntities.SaveChanges();
                    string category = newsType.GetByID(x => x.Id == newsPost.CategoryId).NewsType;
                    var    webadrs  = ConfigurationManager.AppSettings["webid"];
                    Task.Factory.StartNew(() => new apiPlugin().pagePublish(newsPost.OdiaTitle, (webadrs + "/News/" + category + "/" + newsPost.PostedYear + "/" + newsPost.PostedMonth + "/" + Id + "/" + newsPost.SlugUrl)));
                }
                Task.Factory.StartNew(() => new NewsOprations().UpdateData());

                return(Json(new { msg = "Post Approved Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
            return(Json(new { msg = "Post Approve Unsucessful" }, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
 public void Edit(T entity)
 {
     _table.Attach(entity);
     _context.Entry(entity).State = EntityState.Modified;
 }
예제 #3
0
        public ContentResult HeaderImageUpload()
        {
            NewsPost nps = new NewsPost();

            try
            {
                int    NewsId     = 0;
                string FolderName = "";
                string path       = "";
                if (Request.Params["newsID"] == "0")
                {
                    using (NewsPortalEntities portalEntities = new NewsPortalEntities())
                    {
                        NewsId = portalEntities.NewsPosts.Where(x => x.PostedDate.Value.Year == DateTime.Now.Year && x.PostedDate.Value.Month == DateTime.Now.Month && x.PostedDate.Value.Day == DateTime.Now.Day).ToList().Count;
                    }
                    NewsId = NewsId + 1;

                    FolderName = DateTime.Now.Date.ToString("ddMMyyyy");
                    path       = Server.MapPath("~/Uploads/" + FolderName + "/" + NewsId);
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                }
                else
                {
                    using (NewsPortalEntities portalEntities = new NewsPortalEntities())
                    {
                        decimal newsID = Convert.ToDecimal(Request.Params["newsID"]);
                        nps = portalEntities.NewsPosts.Where(x => x.Id == newsID).FirstOrDefault();
                        string ImageName = "";
                        if (nps != null)
                        {
                            DeleteImage(nps.HeaderImageName);
                            ImageName  = nps.HeaderImageName;
                            FolderName = ImageName.Split('/')[0];
                            NewsId     = int.Parse(ImageName.Split('/')[1]);
                        }
                    }
                    path = Server.MapPath("~/Uploads/" + FolderName + "/" + NewsId);
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                }
                string ImageUrl = "";
                string filename = "";
                string imgId    = DateTime.Now.Hour + "" + DateTime.Now.Minute;
                foreach (string key in Request.Files)
                {
                    HttpPostedFileBase postedFile = Request.Files[key];
                    ImageUrl = Path.Combine(path, "Img_" + imgId + ".jpg");
                    Stream strm     = postedFile.InputStream;
                    int    flstatus = GenerateThumbnails(0.2, strm, ImageUrl, 400, 210);
                    filename = postedFile.FileName;
                    CreateThumbnail(postedFile, NewsId, FolderName, imgId);
                    CreateThumbnail279(postedFile, NewsId, FolderName, imgId);
                    CreateThumbnail210(postedFile, NewsId, FolderName, imgId);
                }
                if (Request.Params["newsID"] != "0")
                {
                    string Image = FolderName + "/" + NewsId + "/" + "Img_" + imgId + ".jpg";
                    using (NewsPortalEntities portalEntities = new NewsPortalEntities())
                    {
                        decimal  newsID   = Convert.ToDecimal(Request.Params["newsID"]);
                        NewsPost newsPost = portalEntities.NewsPosts.Where(x => x.Id == newsID).FirstOrDefault();
                        newsPost.HeaderImageName = Image;
                        newsPost.Thumbnail86     = Image.Replace("Img", "Thumbnail_86x64");
                        newsPost.Thumbnail210    = Image.Replace("Img", "Thumbnail_210x136");
                        newsPost.Thumbnail279    = Image.Replace("Img", "Thumbnail_279x220");
                        portalEntities.NewsPosts.Attach(newsPost);
                        portalEntities.Entry(newsPost).State = EntityState.Modified;
                        portalEntities.SaveChanges();
                    }
                }
                return(Content(FolderName + "/" + NewsId + "/" + "Img_" + imgId + ".jpg"));
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
            return(null);
        }
예제 #4
0
 public JsonResult UpdatePost(ClsPost clsPost)
 {
     try
     {
         var currentUser = (ClaimsPrincipal)Thread.CurrentPrincipal;
         var UserId      = currentUser.Claims.Where(x => x.Type == ClaimTypes.PrimarySid).Select(c => c.Value).SingleOrDefault();
         var Role        = currentUser.Claims.Where(x => x.Type == ClaimTypes.Role).Select(c => c.Value).SingleOrDefault();
         clsPost.IsReviewed = false;
         if (clsPost.IsSchedule == false)
         {
             if (Role == "SuperAdmin" || Role == "Admin")
             {
                 clsPost.ReviewedBy = int.Parse(UserId);
                 clsPost.IsReviewed = true;
             }
         }
         clsPost.Modified = DateTime.Now;
         bool IsReviewed = false;
         using (NewsPortalEntities portalEntities = new NewsPortalEntities())
         {
             NewsPost newsPost = portalEntities.NewsPosts.Where(x => x.Id == clsPost.Id).FirstOrDefault();
             IsReviewed               = newsPost.IsReviewed.Value;
             newsPost.EnglishTitle    = clsPost.EnglishTitle;
             newsPost.OdiaTitle       = clsPost.OdiaTitle;
             newsPost.EngShortDesc    = clsPost.EngShortDesc;
             newsPost.ODShortDesc     = clsPost.ODShortDesc;
             newsPost.SeoMeta         = clsPost.SeoMeta;
             newsPost.Tags            = clsPost.Tags;
             newsPost.CategoryId      = clsPost.CategoryId;
             newsPost.HeaderImageName = clsPost.ImageName;
             newsPost.ODContent       = clsPost.ODContent;
             newsPost.IsReviewed      = clsPost.IsReviewed;
             newsPost.ReviewedBy      = clsPost.ReviewedBy;
             newsPost.ModifiedOn      = clsPost.Modified;
             newsPost.Thumbnail86     = clsPost.ImageName.Replace("Img", "Thumbnail_86x64");
             newsPost.Thumbnail210    = clsPost.ImageName.Replace("Img", "Thumbnail_210x136");
             newsPost.Thumbnail279    = clsPost.ImageName.Replace("Img", "Thumbnail_279x220");
             newsPost.SlugUrl         = UrlGenerator.GetUrl(clsPost.EnglishTitle);
             portalEntities.NewsPosts.Attach(newsPost);
             portalEntities.Entry(newsPost).State = EntityState.Modified;
             portalEntities.SaveChanges();
             //if(IsReviewed==false)
             {
                 if (Role == "SuperAdmin" || Role == "Admin")
                 {
                     string category = newsType.GetByID(x => x.Id == newsPost.CategoryId).NewsType;
                     var    webadrs  = ConfigurationManager.AppSettings["webid"];
                     Task.Factory.StartNew(() => new apiPlugin().pagePublish(newsPost.OdiaTitle, (webadrs + "/News/" + category + "/" + newsPost.PostedYear + "/" + newsPost.PostedMonth + "/" + clsPost.Id + "/" + newsPost.SlugUrl)));
                 }
             }
         }
         Task.Factory.StartNew(() => new NewsOprations().UpdateData());
         if (clsPost.IsSchedule == true)
         {
             try
             {
                 SchdulePostConfig schPostConfig = schulepostconfig.GetByID(x => x.PostId == clsPost.Id);
                 if (schPostConfig != null)
                 {
                     schPostConfig.PostId       = clsPost.Id;
                     schPostConfig.PostedOn     = DateTime.Now;
                     schPostConfig.ScheduleTime = DateTime.Now.AddHours(clsPost.Delay);
                     schPostConfig.TimeDelay    = clsPost.Delay;
                     schulepostconfig.Edit(schPostConfig);
                     schulepostconfig.Save();
                 }
                 else
                 {
                     SchdulePostConfig scPostConfig = new SchdulePostConfig();
                     scPostConfig.PostId       = clsPost.Id;
                     scPostConfig.PostedOn     = DateTime.Now;
                     scPostConfig.ScheduleTime = DateTime.Now.AddHours(clsPost.Delay);
                     scPostConfig.TimeDelay    = clsPost.Delay;
                     schulepostconfig.Insert(scPostConfig);
                     schulepostconfig.Save();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error("Update News schdule issue", ex);
             }
         }
         else
         {
             try
             {
                 SchdulePostConfig schPostConfig = schulepostconfig.GetByID(x => x.PostId == clsPost.Id);
                 if (schPostConfig != null)
                 {
                     schulepostconfig.Delete(x => x.PostId == clsPost.Id);
                     schulepostconfig.Save();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error("Delete News schdule issue", ex);
             }
         }
         return(Json(new { msg = "Post Updated Successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
     return(Json(new { msg = "Post Updation Unsucessful" }, JsonRequestBehavior.AllowGet));
 }