public decimal NewsPost(ClsPost objclsPost) { try { using (NewsPortalEntities portalEntities = new NewsPortalEntities()) { NewsPost newsPost = new NewsPost(); newsPost.EnglishTitle = objclsPost.EnglishTitle; newsPost.OdiaTitle = objclsPost.OdiaTitle; newsPost.EngShortDesc = objclsPost.EngShortDesc; newsPost.ODShortDesc = objclsPost.ODShortDesc; newsPost.SeoMeta = objclsPost.SeoMeta; newsPost.Tags = objclsPost.Tags; newsPost.CategoryId = objclsPost.CategoryId; newsPost.HeaderImageName = objclsPost.ImageName; newsPost.ODContent = objclsPost.ODContent; newsPost.IsActive = true; newsPost.IsDeleted = false; newsPost.IsReviewed = objclsPost.IsReviewed; newsPost.CreatedBy = objclsPost.CreatedBy; newsPost.ReviewedBy = objclsPost.ReviewedBy; newsPost.PostedDate = objclsPost.PostedDate; newsPost.PostedOn = objclsPost.PostedOn; newsPost.PostedMonth = objclsPost.PostedMonth; newsPost.PostedYear = objclsPost.PostedYear; newsPost.SlugUrl = objclsPost.SlugUrl; newsPost.Thumbnail86 = objclsPost.ImageName.Replace("Img", "Thumbnail_86x64"); newsPost.Thumbnail210 = objclsPost.ImageName.Replace("Img", "Thumbnail_210x136"); newsPost.Thumbnail279 = objclsPost.ImageName.Replace("Img", "Thumbnail_279x220"); newsPost.Frequency = 0; portalEntities.NewsPosts.Add(newsPost); portalEntities.SaveChanges(); return(newsPost.Id); } } catch (Exception ex) { Log.Error(ex.ToString()); } return(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)); }
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)); }