public QueryResponce <T> DoQuery() { var urlGenerator = new UrlGenerator() { Options = Options, StructureType = typeof(T) }; var url = urlGenerator.GetUrl(); var client = new QueryClient() { Url = url }; var textResult = ""; textResult = client.DoQuery(); if (string.IsNullOrEmpty(textResult)) { var nullResult = new QueryResponce <T>() { Data = new List <T>(), Length = 0, Pagination = null, Url = url }; return(nullResult); } var json = JsonConvert.DeserializeObject <QueryResponce <T> >(textResult); json.Url = url; return(json); }
public QueryResponce <T> GetEmptyQuery() { var urlGenerator = new UrlGenerator() { Options = Options, StructureType = typeof(T) }; var url = urlGenerator.GetUrl(); var nullResult = new QueryResponce <T>() { Data = new List <T>(), Length = 0, Pagination = null, Url = url }; return(nullResult); }
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)); }