public JsonResult Delete(int?CategoriesId) { Session["Edit/Delete"] = "Delete"; var rvd = new RouteValueDictionary(); int?Page = 1; var page = Request.QueryString["page"] ?? Models.Common._currentPage.ToString(); var pagesize = Request.QueryString["pagesize"] ?? Models.Common._pageSize.ToString(); rvd.Add("page", Page); rvd.Add("Column", Request.QueryString["Column"] != null ? Request.QueryString["Column"].ToString() : "CategoryNameTxt"); rvd.Add("Direction", Request.QueryString["Direction"] != null ? Request.QueryString["Direction"].ToString() : "Ascending"); rvd.Add("pagesize", pagesize); var CategoriesContext = new Contexts.CategoriesContexts(); var BlogsContexts = new Contexts.BlogsContexts(); if (CategoriesId.HasValue) { try { if (CategoriesContext != null) { var counts = BlogsContexts.GetBlogs().Where(x => x.CategoryID == CategoriesId).Select(x => x.CategoryID).Count(); if (counts > 0) { TempData["Message"] = "Category can not be deleted as it contains blog details."; return(Json(Url.Action("BlogCategoriesListing", "Categories", rvd))); } else { CategoriesContext.DeleteCategories(CategoriesId); TempData["AlertMessage"] = "Category deleted successfully."; } } } catch { TempData["AlertMessage"] = "Some error occured while deleting the Category, Please try again later."; } } var count = 1; count = CategoriesContext.GetCategories().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("BlogCategoriesListing", "Categories", rvd))); }
public ActionResult CreateCategories(int?Categoriesid) { Session["Edit/Delete"] = "Edit"; var _CategoriesContext = new Contexts.CategoriesContexts(); var _CategoriesModel = new CategoriesModel(); ViewBag.Title = (Categoriesid.HasValue && Categoriesid.Value > 0 ? "Edit " : "Add ") + " Category"; ViewBag.Submit = Categoriesid.HasValue && Categoriesid.Value > 0 ? "Update" : "Save"; if (Categoriesid.HasValue && Categoriesid.Value > 0) { if (_CategoriesModel != null) { _CategoriesModel = _CategoriesContext.GetCategories().Where(x => x.CategoryID == Categoriesid).FirstOrDefault(); } } return(View(_CategoriesModel)); }
public ActionResult CreateCategories(CategoriesModel _Categoriesmodel, string command, FormCollection fm) { Session["Edit/Delete"] = "Edit"; ViewBag.Title = (_Categoriesmodel.CategoryID > 0 ? "Edit " : "Add ") + " Category "; ViewBag.Submit = _Categoriesmodel.CategoryID > 0 ? "Update" : "Save"; var CategoriesContext = new Contexts.CategoriesContexts(); if (string.IsNullOrEmpty(command)) { if (CategoriesContext.GetCategories().Where(x => x.CategoryNameTxt.ToLower().Trim() == _Categoriesmodel.CategoryNameTxt.ToLower().Trim() && _Categoriesmodel.CategoryID != x.CategoryID).Any()) { ModelState.AddModelError("CategoryNameTxt", _Categoriesmodel.CategoryNameTxt + " category already exists."); return(View(_Categoriesmodel)); } try { _Categoriesmodel.CategoryNameTxt = _Categoriesmodel.CategoryNameTxt.Trim(); if (ViewBag.Submit == "Save") { CategoriesContext.AddCategories(_Categoriesmodel); TempData["AlertMessage"] = "Category saved successfully."; } else { CategoriesContext.EditCategories(_Categoriesmodel); TempData["AlertMessage"] = "Category updated successfully."; } } catch (Exception ex) { TempData["AlertMessage"] = "Some error occured, Please try after some time. " + ex.Message.ToString(); } } var rvd = new RouteValueDictionary(); rvd.Add("Column", Request.QueryString["Column"] != null ? Request.QueryString["Column"].ToString() : "CategoryNameTxt"); 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("BlogCategoriesListing", "Categories", 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 CreateBlog(int?Blogid) { var _BlogsContexts = new Contexts.BlogsContexts(); var _CategoriesContexts = new Contexts.CategoriesContexts(); var _UsersContexts = new Contexts.UsersContexts(); var _BlogsModel = new BlogsModel(); ViewBag.Title = (Blogid.HasValue ? "Edit " : "Add ") + " Post Details "; ViewBag.Submit = Blogid.HasValue && Blogid.Value > 0 ? "Update" : "Save"; bool isActive = true, allowComments = true; _BlogsModel.TagList = GetAllTags(); _BlogsModel.SocialMediaList = GetAllSocialMedia(); try { var taglist = ViewBag.Tag = string.Join(",", _BlogsModel.TagList.Select(x => x.Text)); if (Blogid.HasValue && Blogid.Value > 0) { _BlogsModel = _BlogsContexts.GetBlogs().Where(x => x.BlogID == Blogid).FirstOrDefault(); if (_BlogsModel != null) { isActive = _BlogsModel.IsActiveInd; allowComments = _BlogsModel.IsCommentEnabledInd; _BlogsModel.strCategoryid = Convert.ToString(_BlogsModel.CategoryID); var selecetdtagNamearray = Array.ConvertAll <string, string>(_BlogsContexts.GetFormBlogTags(Blogid.Value).ToArray(), delegate(string i) { return((string)i.ToString()); }); var selecetdtagIDarray = Array.ConvertAll <string, string>(_BlogsContexts.GetFormBlogTagsIDList(Blogid.Value).ToArray(), delegate(string i) { return((string)i.ToString()); }); var selecetdSocialMediasarray = Array.ConvertAll <int, string>(_BlogsContexts.GetFormBlogSocialMedia(Blogid.Value).ToArray(), delegate(int i) { return((string)i.ToString()); }); var UserList = _UsersContexts.GetUser(_BlogsModel.AuthorNameTxt); //User list based on userid _BlogsModel.AuthorNameID = Convert.ToString(UserList != null ? UserList.UserID : 0); //UserID ViewBag.Category = new SelectList(_CategoriesContexts.GetSelectedCategories(Convert.ToString(_BlogsModel.CategoryID)), "CategoryID", "CategoryNameTxt"); ViewBag.AuthorName = new SelectList(_UsersContexts.GetUserList(_BlogsModel.AuthorNameID), "UserID", "UserNameTxt"); //Author drop down listing _BlogsModel.TagList = GetAllTags(); _BlogsModel.SocialMediaList = GetAllSocialMedia(); _BlogsModel.SelectedTags = selecetdtagNamearray; _BlogsModel.SelectedTagsID = selecetdtagIDarray; _BlogsModel.SelectedSocialMedia = selecetdSocialMediasarray; } } else { ViewBag.Category = new SelectList(_CategoriesContexts.GetSelectedCategories(string.Empty), "CategoryID", "CategoryNameTxt"); ViewBag.AuthorName = new SelectList(_UsersContexts.GetUserList(string.Empty), "UserID", "UserNameTxt");//Author drop down listing string[] Tagsarr = new string[] { "0" }; _BlogsModel.SelectedTagsID = Tagsarr; } } catch (Exception ex) { ViewBag.Category = new SelectList(_CategoriesContexts.GetSelectedCategories(string.Empty), "CategoryID", "CategoryNameTxt"); ViewBag.AuthorName = new SelectList(_UsersContexts.GetUserList(string.Empty), "UserID", "UserNameTxt");//Author drop down listing string[] Tagsarr = new string[] { "0" }; _BlogsModel.SelectedTagsID = Tagsarr; } ViewBag.IsCommentEnabledInd = Models.Common.GetStatusListBoolean(allowComments ? "true" : "false"); ViewBag.IsActiveInd = Models.Common.GetStatusListBoolean(isActive ? "true" : "false"); return(View(_BlogsModel)); }
public ActionResult BlogCategoriesListing(GridSortOptions gridSortOptions, int?pagetype, int?page, int?pagesize, FormCollection fm, string objresult) { var _objContext = new Contexts.CategoriesContexts(); ViewBag.Title = " Categories Listing"; var _CategoriesModel = new CategoriesModel(); #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 == "CategoryNameTxt") { } else { gridSortOptions.Column = "CategoryNameTxt"; } var pagedViewModel = new PagedViewModel <CategoriesModel> { ViewData = ViewData, Query = _objContext.GetCategories().AsQueryable(), GridSortOptions = gridSortOptions, DefaultSortColumn = "CategoryNameTxt", Page = Page, PageSize = PageSize, }.Setup(); if (Request.IsAjaxRequest()) // check if request comes from ajax, then return Partial view { return(View("BlogCategoriesListingPartial", pagedViewModel)); // ("partial view name ") } else { return(View(pagedViewModel)); } }