public JsonResult GetNewsById(int?Id) { try { NewsPost newstyp = newsPost.GetByID(x => x.Id == Id); SchdulePostConfig schPostConfig = schulepostconfig.GetByID(x => x.PostId == Id); return(Json(new { _newspost = newstyp, _npsc = schPostConfig }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Log.Error(ex.ToString()); } return(null); }
public JsonResult DeletePost(int?Id) { try { NewsPost newstyp = newsPost.GetByID(x => x.Id == Id); if (newstyp != null) { newsPost.Delete(x => x.Id == Id); newsPost.Save(); Task.Factory.StartNew(() => new NewsOprations().UpdateData()); if (!string.IsNullOrEmpty(newstyp.HeaderImageName)) { DeleteImage(newstyp.HeaderImageName); } } try { SchdulePostConfig schPostConfig = schulepostconfig.GetByID(x => x.PostId == Id); if (schPostConfig != null) { schulepostconfig.Delete(x => x.PostId == Id); schulepostconfig.Save(); } } catch (Exception ex) { Log.Error(ex.ToString()); } return(Json(new { msg = "Post Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Log.Error(ex.ToString()); } return(Json(new { msg = "Post Deletion Unsucessful" }, JsonRequestBehavior.AllowGet)); }
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)); }
public JsonResult NewsPost(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; clsPost.CreatedBy = int.Parse(UserId); if (clsPost.IsSchedule == false) { if (Role == "SuperAdmin" || Role == "Admin") { clsPost.ReviewedBy = int.Parse(UserId); clsPost.IsReviewed = true; } } clsPost.PostedOn = DateTime.Now; clsPost.PostedDate = DateTime.Now; clsPost.PostedYear = DateTime.Now.Year; clsPost.PostedMonth = DateTime.Now.Month; clsPost.SlugUrl = UrlGenerator.GetUrl(clsPost.EnglishTitle); NewsOprations oprations = new NewsOprations(); decimal i = oprations.NewsPost(clsPost); if (i > 0) { Task.Factory.StartNew(() => new NewsOprations().UpdateData()); if (clsPost.IsSchedule == true) { try { SchdulePostConfig schPostConfig = new SchdulePostConfig(); if (schPostConfig != null) { schPostConfig.PostId = i; schPostConfig.PostedOn = DateTime.Now; schPostConfig.ScheduleTime = DateTime.Now.AddHours(clsPost.Delay); schPostConfig.TimeDelay = clsPost.Delay; schulepostconfig.Insert(schPostConfig); schulepostconfig.Save(); } } catch (Exception ex) { Log.Error(ex.ToString()); } } if (clsPost.IsSchedule == false) { if (Role == "SuperAdmin" || Role == "Admin") { if (clsPost.IsFacebookPublish == true) { string category = newsType.GetByID(x => x.Id == clsPost.CategoryId).NewsType; var webadrs = ConfigurationManager.AppSettings["webid"]; Task.Factory.StartNew(() => new apiPlugin().pagePublish(clsPost.OdiaTitle, (webadrs + "/News/" + category + "/" + clsPost.PostedYear + "/" + clsPost.PostedMonth + "/" + i + "/" + clsPost.SlugUrl))); } } } return(Json(new { msg = "News Posted Successfully..." }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { msg = "News Posted UnSuccessful..." }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Log.Error(ex.ToString()); } return(Json(new { msg = "News Posted UnSuccessful..." }, JsonRequestBehavior.AllowGet)); }