public FormBlogTags(int BlogTagID, int BlogID, string TagID) { var _TagContexts = new Contexts.TagsContexts(); this.BlogTagID = BlogTagID; this.BlogID = BlogID; this.TagID = TagID; this.TagModel = _TagContexts.GetTags().AsEnumerable(); }
private SelectList GetAllTags() { var _TagContexts = new Contexts.TagsContexts(); var list = _TagContexts.GetTags().OrderBy(x => x.TagNameTxt).Select(x => new TagsModel() { TagID = x.TagID, TagNameTxt = x.TagNameTxt }).ToList(); var objselectlist = new SelectList(list, "TagID", "TagNameTxt"); return(objselectlist); }
public JsonResult Delete(int?TagsId) { Session["Edit/Delete"] = "delete"; var page = Request.QueryString["page"] ?? Models.Common._currentPage.ToString(); var pagesize = Request.QueryString["pagesize"] ?? Models.Common._pageSize.ToString(); var rvd = new RouteValueDictionary(); int?Page = 1; rvd.Add("page", Page); rvd.Add("Column", Request.QueryString["Column"] != null ? Request.QueryString["Column"].ToString() : "TagNameTxt"); rvd.Add("Direction", Request.QueryString["Direction"] != null ? Request.QueryString["Direction"].ToString() : "Ascending"); rvd.Add("pagesize", pagesize); var TagsContext = new Contexts.TagsContexts(); var BlogsContexts = new Contexts.BlogsContexts(); if (TagsId.HasValue) { try { if (TagsContext != null) { var counts = BlogsContexts.GetFormBlogTagList(TagsId.Value).Count(); if (counts > 0) { TempData["Message"] = "Tag can not be deleted as it contains blog details."; return(Json(Url.Action("BlogTagsListing", "Tags", rvd))); } else { TagsContext.DeleteTags(TagsId); TempData["AlertMessage"] = "Tag deleted successfully."; } } } catch { TempData["AlertMessage"] = "Some error occured while deleting the Tag, Please try again later."; } } var count = 1; count = TagsContext.GetTags().Count(); if (Convert.ToInt32(page) > 1) { Page = count > ((Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize)) ? Convert.ToInt32(page) : (Convert.ToInt32(page)) - 1; } return(Json(Url.Action("BlogTagsListing", "Tags", rvd))); }
public ActionResult CreateTags(int?Tagsid) { Session["Edit/Delete"] = "Edit"; var _TagsContext = new Contexts.TagsContexts(); var _TagsModel = new TagsModel(); ViewBag.Title = (Tagsid.HasValue && Tagsid.Value > 0 ? "Edit " : "Add ") + " Tag "; ViewBag.Submit = Tagsid.HasValue && Tagsid.Value > 0 ? "Update" : "Save"; if (Tagsid.HasValue && Tagsid.Value > 0) { if (_TagsModel != null) { _TagsModel = _TagsContext.GetTags().Where(x => x.TagID == Tagsid).FirstOrDefault(); } } return(View(_TagsModel)); }
public ActionResult CreateTags(TagsModel _Tagsmodel, string command, FormCollection fm) { Session["Edit/Delete"] = "Edit"; ViewBag.Title = (_Tagsmodel.TagID > 0 ? "Edit " : "Add ") + " Tag "; ViewBag.Submit = _Tagsmodel.TagID > 0 ? "Update" : "Save"; var TagsContext = new Contexts.TagsContexts(); if (string.IsNullOrEmpty(command)) { if (TagsContext.GetTags().Where(x => x.TagNameTxt.ToLower().Trim() == _Tagsmodel.TagNameTxt.ToLower().Trim() && _Tagsmodel.TagID != x.TagID).Any()) { ModelState.AddModelError("TagNameTxt", _Tagsmodel.TagNameTxt + " tag already exists."); return(View(_Tagsmodel)); } try { _Tagsmodel.TagNameTxt = _Tagsmodel.TagNameTxt.Trim(); if (ViewBag.Submit == "Save") { TagsContext.AddTags(_Tagsmodel); TempData["AlertMessage"] = "Tag saved successfully."; } else { TagsContext.EditTags(_Tagsmodel); TempData["AlertMessage"] = "Tag updated successfully."; } } catch { TempData["AlertMessage"] = "Some error occured, Please try after some time."; } } var rvd = new RouteValueDictionary(); rvd.Add("Column", Request.QueryString["Column"] != null ? Request.QueryString["Column"].ToString() : "TagNameTxt"); rvd.Add("Direction", Request.QueryString["Direction"] != null ? Request.QueryString["Direction"].ToString() : "Ascending"); rvd.Add("pagesize", Request.QueryString["pagesize"] != null ? Request.QueryString["pagesize"].ToString() : Models.Common._pageSize.ToString()); rvd.Add("page", Request.QueryString["page"] != null ? Request.QueryString["page"].ToString() : Models.Common._currentPage.ToString()); return(RedirectToAction("BlogTagsListing", "Tags", rvd)); }
public ActionResult CreateBlog(BlogsModel _Blogsmodel, string command, FormCollection fm) { Session["Edit/Delete"] = "Edit"; var file = Request.Files.Count > 0 ? Request.Files[0] : null; ViewBag.Title = (_Blogsmodel.BlogID > 0 ? "Edit " : "Add ") + " Post Details "; ViewBag.Submit = _Blogsmodel.BlogID > 0 ? "Update" : "Save"; bool isActive = true, allowComments = true; _Blogsmodel.TagList = GetAllTags(); var _UsersContexts = new Contexts.UsersContexts(); var _CategoriesContexts = new Contexts.CategoriesContexts(); var BlogsContext = new Contexts.BlogsContexts(); var TagContext = new Contexts.TagsContexts(); ViewBag.AuthorName = new SelectList(_UsersContexts.GetUserList(_Blogsmodel.AuthorNameID), "UserID", "UserNameTxt");//Author drop down listing ViewBag.Category = new SelectList(_CategoriesContexts.GetSelectedCategories(string.Empty), "CategoryID", "CategoryNameTxt"); if (string.IsNullOrEmpty(command)) { isActive = _Blogsmodel.IsActiveInd; allowComments = _Blogsmodel.IsCommentEnabledInd; ViewBag.IsCommentEnabledInd = Models.Common.GetStatusListBoolean(allowComments ? "true" : "false"); ViewBag.IsActiveInd = Models.Common.GetStatusListBoolean(isActive ? "true" : "false"); _Blogsmodel.SocialMediaList = GetAllSocialMedia(); _Blogsmodel.strCategoryid = Convert.ToString(_Blogsmodel.strCategoryid); if (BlogsContext.GetBlogs().Where(x => x.TitleTxt == _Blogsmodel.TitleTxt && _Blogsmodel.BlogID != x.BlogID).Any()) { ModelState.AddModelError("TitleTxt", _Blogsmodel.TitleTxt + " Post already exists."); return(View(_Blogsmodel)); } if (_Blogsmodel.SlagTxt.ToLower() == "error404") //check 404 error { ModelState.AddModelError("SlagTxt", _Blogsmodel.SlagTxt + " URL is not allowed."); return(View(_Blogsmodel)); } try { //Save image path if (file != null && file.ContentLength > 0) { #region Upload Image Models.Common.CreateFolder(); var croppedfile = new System.IO.FileInfo(Server.MapPath(TempData["CroppedImage"].ToString())); var fileName = croppedfile.Name; croppedfile = null; var sourcePath = Server.MapPath(TempData["CroppedImage"].ToString()); var targetPath = Request.PhysicalApplicationPath + "WebData\\"; System.IO.File.Copy(System.IO.Path.Combine(sourcePath.Replace(fileName, ""), fileName), System.IO.Path.Combine(targetPath + "images\\", fileName), true); try { Models.Common.DeleteImage(Server.MapPath(TempData["CroppedImage"].ToString())); } catch { } TempData["CroppedImage"] = null; _Blogsmodel.ImagePathTxt = "~/WebData/images/" + fileName; var width = 250; var fileExtension = fileName.Substring(fileName.LastIndexOf("."), fileName.Length - fileName.LastIndexOf(".")); var strPath = Request.PhysicalApplicationPath + "WebData\\images\\" + fileName; var myImage = Models.Common.CreateImageThumbnail(strPath, width); myImage.Save(Request.PhysicalApplicationPath + "WebData\\thumbnails\\" + fileName, fileExtension.ToLower() == ".png" ? System.Drawing.Imaging.ImageFormat.Png : fileExtension.ToLower() == ".gif" ? System.Drawing.Imaging.ImageFormat.Gif : System.Drawing.Imaging.ImageFormat.Jpeg ); myImage.Dispose(); var mysmallImage = Models.Common.CreateImageThumbnail(strPath, 200); mysmallImage.Save(Request.PhysicalApplicationPath + "WebData\\thumbnails_Small\\" + fileName, fileExtension.ToLower() == ".png" ? System.Drawing.Imaging.ImageFormat.Png : fileExtension.ToLower() == ".gif" ? System.Drawing.Imaging.ImageFormat.Gif : System.Drawing.Imaging.ImageFormat.Jpeg ); mysmallImage.Dispose(); #endregion } else { _Blogsmodel.ImagePathTxt = BlogsContext.GetBlogs().Where(x => x.BlogID == _Blogsmodel.BlogID).Select(x => x.ImagePathTxt).FirstOrDefault(); } if (ViewBag.Submit == "Save") { BlogsContext.AddBlogs(_Blogsmodel); TempData["AlertMessage"] = "Post details saved successfully."; } else { BlogsContext.EditBlogs(_Blogsmodel, false); TempData["AlertMessage"] = "Post details updated successfully."; } } catch (Exception ex) { TempData["AlertMessage"] = "Some error occured, Please try after some time. " + ex.Message; } } var rvd = new RouteValueDictionary(); rvd.Add("Column", Request.QueryString["Column"] != null ? Request.QueryString["Column"].ToString() : "PostedDate"); rvd.Add("Direction", Request.QueryString["Direction"] != null ? Request.QueryString["Direction"].ToString() : "Descending"); rvd.Add("pagesize", Request.QueryString["pagesize"] != null ? Request.QueryString["pagesize"].ToString() : Models.Common._pageSize.ToString()); rvd.Add("page", Request.QueryString["page"] != null ? Request.QueryString["page"].ToString() : Models.Common._currentPage.ToString()); return(RedirectToAction("BlogsListing", "Blogs", rvd)); }
public ActionResult BlogTagsListing(GridSortOptions gridSortOptions, int?pagetype, int?page, int?pagesize, FormCollection fm, string objresult) { var _objContext = new Contexts.TagsContexts(); ViewBag.Title = " Tags Listing"; var _TagsModel = new TagsModel(); #region Ajax Call if (objresult != null) { AjaxRequest objAjaxRequest = JsonConvert.DeserializeObject <AjaxRequest>(objresult);//Convert json String to object Model if (objAjaxRequest.ajaxcall != null && !string.IsNullOrEmpty(objAjaxRequest.ajaxcall) && objresult != null && !string.IsNullOrEmpty(objresult)) { if (objAjaxRequest.ajaxcall == "paging") //Ajax Call type = paging i.e. Next|Previous|Back|Last { Session["pageNo"] = page; // stores the page no for status } else if (objAjaxRequest.ajaxcall == "sorting") //Ajax Call type = sorting i.e. column sorting Asc or Desc { page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : page); Session["GridSortOption"] = gridSortOptions; pagesize = (Session["PageSize"] != null ? Convert.ToInt32(Session["PageSize"].ToString()) : pagesize); } else if (objAjaxRequest.ajaxcall == "ddlPaging")//Ajax Call type = drop down paging i.e. drop down value 10, 25, 50, 100, ALL { Session["PageSize"] = (Request.QueryString["pagesize"] != null ? Convert.ToInt32(Request.QueryString["pagesize"].ToString()) : pagesize); Session["GridSortOption"] = gridSortOptions; Session["pageNo"] = page; } else if (objAjaxRequest.ajaxcall == "status")//Ajax Call type = status i.e. Active/Inactive { page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : page); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); } else if (objAjaxRequest.ajaxcall == "displayorder")//Ajax Call type = Display Order i.e. drop down values { page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : page); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); } objAjaxRequest.ajaxcall = null;; //remove parameter value } } #endregion Ajax Call //This section is used to retain the values of page , pagesize and gridsortoption on complete page post back(Edit, Dlete) //Pass value for Session["Edit/Delete"] from Edit and delete action on postback if (!Request.IsAjaxRequest() && Session["Edit/Delete"] != null && !string.IsNullOrEmpty(Session["Edit/Delete"].ToString())) { pagesize = (Session["PageSize"] != null ? Convert.ToInt32(Session["PageSize"]) : Models.Common._pageSize); page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"]) : Models.Common._currentPage); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); Session["Edit/Delete"] = null; } else if (!Request.IsAjaxRequest() && Session["Edit/Delete"] == null) { //gridSortOptions.Column = "CreateDate"; Session["PageSize"] = null; Session["pageNo"] = null; Session["GridSortOption"] = null; } var PageSize = pagesize.HasValue ? pagesize.Value : Models.Common._pageSize; var Page = page.HasValue ? page.Value : Models.Common._currentPage; TempData["pager"] = pagesize; if (gridSortOptions.Column != null && gridSortOptions.Column == "TagNameTxt") { } else { gridSortOptions.Column = "TagNameTxt"; } var pagedViewModel = new PagedViewModel <TagsModel> { ViewData = ViewData, Query = _objContext.GetTags().AsQueryable(), GridSortOptions = gridSortOptions, DefaultSortColumn = "TagNameTxt", Page = Page, PageSize = PageSize, }.Setup(); if (Request.IsAjaxRequest()) // check if request comes from ajax, then return Partial view { return(View("BlogTagsListingPartial", pagedViewModel)); // ("partial view name ") } else { return(View(pagedViewModel)); } }