Sourabh Choubey

Sourabh Choubey

  • NA
  • 145
  • 6.8k

format issue is correct

Mar 6 2018 2:03 AM
@using Testing.Areas.Admin.Models;
@model CategoryModel
@{
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
string example = "From Youtube choose share and embed. Then Copy the data and paste in the video Link box aove";
Model.ParentCategories = new List<SelectListItem>
{
new SelectListItem { Value = "1", Text = "[None]" },
new SelectListItem { Value = "2", Text = "Admin" },
new SelectListItem { Value = "3", Text = "Staff" },
};
}
<link href="@Url.Content("~/Areas/Admin/Content/css/bootstrap.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/makeRequest.js")"></script>
@****************************NEW JQUERY***********@
<link rel="stylesheet" href="@Url.Content("~/Content/jQuery/themes/base/jquery.ui.all.css")">
<script type="text/javascript" src="@Url.Content("~/Content/jQuery/jquery-1.7.1.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.core.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.widget.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.datepicker.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.mouse.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.button.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.draggable.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.position.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.resizable.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.ui.dialog.js")"></script>
<script src="@Url.Content("~/Content/jQuery/ui/jquery.effects.core.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@************************************UPLOADIFY***************************************@
<script type="text/javascript" src="@Url.Content("~/Content/jQuery/swfobject.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/jQuery/jquery.uploadify.v2.1.4.min.js")"></script>
@************************************************************************************@
<script type="text/javascript" src="@Url.Content("~/ckeditor/ckeditor.js")"></script>
@****************************************POPUP*******************************@
<link rel="stylesheet" href="@Url.Content("~/Content/jQueryAlert/jquery.alerts.css")">
<script type="text/javascript" src="@Url.Content("~/Content/jQueryAlert/jquery.alerts.js")"></script>
@***************************************************************************@
<link href="@Url.Content("~/Content/fileuploader/uploadfile.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Content/fileuploader/jquery.uploadfile.min.js")"></script>
<script src="@Url.Content("~/Content/fileuploader/plugin.js")"></script>
<div class="boxwrap">
<div class="cormid">
@using (Html.BeginForm("PostPage", "AdminPage"))
{
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.Images)
@Html.HiddenFor(m => m.RemoveImgs)
<div class="ad_detail_contain">
<h3>Add Page </h3>
<div class="create_ad_box">
<div class="search_panel">
</div>
<table style="width: 98%">
<tr style="text-align: center">
<td colspan="2">
<span id="message" style="font-weight: bold"></span>
</td>
</tr>
<tr>
<td><strong>Parent :</strong>
</td>
<td>@Html.DropDownList("SelectedCategoryId", new SelectList(Model.AvailableCategories, "Value", "Text", Model.SelectedCategoryId.ToString()))
</td>
</tr>
<tr>
<td><strong>Page Name :</strong>
</td>
<td>@Html.TextBoxFor(model => model.Name, new { @class = "text"})
</td>
<td style="width: 270px;">@Html.ValidationMessageFor(model => model.Name)</td>
</tr>
<tr>
<td><strong>Meta Title :</strong>
</td>
<td>@Html.TextBoxFor(model => model.MetaTitle, new { @class = "text"})
</td>
<td>
@Html.ValidationMessageFor(model => model.MetaTitle)
</td>
</tr>
<tr>
<td><strong>Seo Keywords :</strong>
</td>
<td>@Html.TextAreaFor(model => model.SeoKeywords, new { @class = "text" , @style="height: 100px; margin-left: 0px; margin-right: 0px;"})
</td>
<td> @Html.ValidationMessageFor(model => model.SeoKeywords)</td>
</tr>
<tr>
<td><strong> Seo Description :</strong>
</td>
<td>@Html.TextAreaFor(model => model.SeoDescription, new { @class = "text" ,@style="height: 100px; margin-left: 0px; margin-right: 0px;"})
</td>
<td> @Html.ValidationMessageFor(model => model.SeoDescription)</td>
</tr>
<tr>
<td width="15%">
<strong>Images [?] :</strong>
</td>
<td>
<div id="fileuploader">Upload </div>
<br />
<span class="text-denger">(Note. Image size: 360 * 500 )</span>
</td>
</tr>
@* <tr>
<td><strong>IsVideo :</strong>
</td>
<td>
@Html.CheckBoxFor(m => m.IsVideo, new { @style=" margin-bottom: 5px; "})
</td>
</tr>*@
@* <tr id="divisnotproduct" >
<td><strong>Video Link :</strong>
</td>
<td>
@Html.TextAreaFor(m => m.LinkName, new { @class = "text" ,@style="width: 732px; height: 100px; margin-left: 0px; margin-right: 0px;"})
<br />
<span >(@example</span>
<br />
<span >Width of the iframe should be 100% .)</span>
</td>
</tr>*@
<tr>
<td><strong>Short Description :</strong>
</td>
<td>
@Html.TextAreaFor(m => m.SortDescription, new { @style="height: 100px; margin-left: 0px; margin-right: 0px;"})
</td>
<td> @Html.ValidationMessageFor(model => model.SortDescription)</td>
</tr>
<tr>
<td><strong>Description :</strong>
</td>
<td>
@Html.TextAreaFor(m => m.Description, new { @class = "ckeditor",@id="editor1" })
</td>
</tr>
<tr>
<td><br /><strong>Display Orders :</strong>
</td>
<td><br />@Html.TextBoxFor(model => model.DisplayOrders, new { @class = "text"})
</td>
<td> @Html.ValidationMessageFor(model => model.DisplayOrders)</td>
</tr>
<tr>
<td><strong>Show On Home Page :</strong>
</td>
<td>@Html.CheckBoxFor(model => model.ShowOnHomePage)
</td>
</tr>
</table>
</div>
<div class="create_ad_box">
</div>
<div style="margin-left: 18%; margin-top: 1%">
<input name="Button1" type="submit" value="Add Page" class="btn btn-primary" />
</div>
</div>
<input type="button" id="trigger" style="display: none;" />
}
</div>
</div>
<script>
function SomeMethod(checkboxInput) {
if (checkboxInput.checked) {
document.getElementById('divisnotproduct').style.display = "block";
} else {
document.getElementById('divisnotproduct').style.display = "none";
}
}
var $xx = jQuery.noConflict();
$xx(document).ready(function () {
CKEDITOR.replace('editor1', {
filebrowserImageBrowseUrl: '@Url.Action("UploadedImages","AdminPage")',
filebrowserImageUploadUrl: '/AdminPage/UploadAsync'
});
@*$xx("#fileuploader").uploadFile({
url: '@Url.Content("~/AdminPage/UploadAsync/")',
fileName: "myfile",
multiple: false,
maxNumberOfFiles: 1,
allowedTypes: "jpg,png,gif,wbmp,bmp,jpeg,swf",
onSuccess: function (files, data, xhr) {
debugger;
var imgs = document.getElementById('Images');
if (imgs.value != null)
imgs.value = imgs.value + '~' + data;
else
imgs.value = data;
var s1 = "removeimg('" + data + "','btn" + data + "')";
var addRemove = $xx("<input type='button' id='btn" + data + "' onclick=" + s1 + " value='Remove' class='ajax-file-upload-red'>")
var addimg = $xx("<img src='../../Content/CatagoryImage/" + data + "' />")
this.statusbar = $xx("div.ajax-file-upload-statusbar:eq(0)");
addRemove.appendTo(this.statusbar);
addimg.appendTo(this.statusbar);
}
});*@
});
function removeimg(name, btn12) {
debugger;
var str = document.getElementById('Images').value;
var pattern = name;
str = str.replace(pattern, '');
document.getElementById('Images').value = str;
var remimgs = document.getElementById('RemoveImgs');
if (remimgs.value != null)
remimgs.value = remimgs.value + '~' + name;
else
remimgs.value = name;
var element = document.getElementById(btn12);
var parent = document.getElementById(btn12).parentNode;
parent.style.display = 'none';
}
</script>
<script>
function updateValue(id, value) {
debugger;
document.getElementById(id).value = value;
}
</script>
<script>
var $model = jQuery.noConflict();
$model("#trigger").click(function () {
jAlert('<img src="../Content/images/ajax-loader-large.gif" height="60" width="60" />', 'Please wait');
$("#popup_ok").hide();
});
function showSuccess(v) {
debugger;
$("#popup_ok").click();
jAlert('A new Banner Has Been Successfully Inserted.', 'Success');
}
</script>
// controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Abacus.DL;
using Abacus.BL;
using Testing.Areas.Admin.Models;
using System.IO;
using MvcPaging;
using Testing.DL;
namespace Abacus.Areas.Admin.Controllers
{
public class AdminPageController : Controller
{
ImagesBL objImagesBL = new ImagesBL();
int pageSize = int.Parse(System.Configuration.ConfigurationManager.AppSettings["pageSize"].ToString());
public string GetCategoryBreadCrumb(Category category, List<Category> cat)
{
CategoryBL db = new CategoryBL();
string result = string.Empty;
while (category != null)
{
if (String.IsNullOrEmpty(result))
result = category.Name;
else
result = category.Name + " >> " + result;
// category = db.getcategoryById(category.ParentID);
category = cat.Where(x => x.ID == category.ParentID && x.ID > 0).SingleOrDefault();
}
return result;
}
public ActionResult Index(string Page_name, int? page)
{
if (Convert.ToBoolean(Session["ValidateLogOn"]) != true)
return RedirectToAction("Index", "LogOn");
CategoryBL db = new CategoryBL();
var model = new CategoryModel();
//model.ParentCategories = new List<SelectListItem> { new SelectListItem { Text = "[None]", Value = "0" } };
int currentPageIndex = page.HasValue ? page.Value : 1;
var categories = db.GetCategoryList().Where(x => x.IsMarketing == false).ToList();
model.AllCategory = categories.OrderByDescending(x => x.ID).ToList();
//categories.Insert(0, new Category { Name = "[None]", ID = 0 });
model.msg = (string)TempData["message"];
model.ListCategoryModel = categories.Select(x =>
{
return new CategoryModel()
{
Name = x.Name,
Id = x.ID,
BreadCrumb = GetCategoryBreadCrumb(x, categories),
numberOfChild = categories.Where(p => p.ParentID == x.ID).Count(),
msg=model.msg,
};
}).OrderBy(a => a.Id).ToList();
var selectList = new List<SelectListItem>();
foreach (var c in categories)
selectList.Add(new SelectListItem()
{
Value = c.ID.ToString(),
Text = GetCategoryBreadCrumb(c, categories),
Selected = true
});
model.AvailableCategories = selectList;
if (string.IsNullOrWhiteSpace(Page_name))
{
model.pageCategoriesList = model.ListCategoryModel.ToPagedList(currentPageIndex, pageSize);
}
else
{
model.pageCategoriesList = (from p in model.ListCategoryModel
where p.Name.Contains(Page_name)
select p).ToPagedList(currentPageIndex, pageSize);
}
if (Request.IsAjaxRequest())
return PartialView("Page", model.pageCategoriesList);
else
return View("~/Areas/Admin/Views/AdminPage/Index.cshtml",model);
}
public ActionResult PostPage()
{
try
{
// Session["categoryId"] = 0;
Session["pageTitle"] = "Add Page";
var model = new CategoryModel();
model.Choice = "Save";
model.selectedPricing = new int[0];
model.Active = false;
CategoryBL db = new CategoryBL();
model.ParentCategories = new List<SelectListItem> { new SelectListItem { Text = "[None]", Value = "0" } };
var categories = db.GetCategoryList().Where(x => x.IsMarketing == false).ToList();
model.AllCategory = categories.ToList();
categories.Insert(0, new Category { Name = "[None]", ID = 0 });
model.ListCategoryModel = categories.Select(x =>
{
return new CategoryModel()
{
Name = x.Name,
Id = x.ID,
BreadCrumb = GetCategoryBreadCrumb(x, categories),
numberOfChild = categories.Where(p => p.ParentID == x.ID).Count(),
};
}).ToList(); ;
var selectList = new List<SelectListItem>();
foreach (var c in categories)
selectList.Add(new SelectListItem()
{
Value = c.ID.ToString(),
Text = GetCategoryBreadCrumb(c, categories),
Selected = true
});
model.AvailableCategories = selectList;
return View("~/Areas/Admin/Views/AdminPage/postPage.cshtml", model);
}
catch
{
return View("~/Views/Shared/Error.cshtml");
}
}
[ValidateInput(false)]
[HttpPost]
public ActionResult PostPage(CategoryModel categoryModel, FormCollection form)
{
CategoryBL db = new CategoryBL();
Session["levelError"] = null;
Session["rowsEffected"] = null;
Session["msetype"] = null;
int res = 0;
int level = 0;
try
{
if (ModelState.IsValid)
{
categoryModel.ParentCategories = new List<SelectListItem> { new SelectListItem { Text = "[None]", Value = "0" } };
var categories = db.GetCategoryList().Where(x => x.IsMarketing == false).ToList();
categoryModel.AllCategory = categories.ToList();
categories.Insert(0, new Category { Name = "[None]", ID = 0 });
categoryModel.ListCategoryModel = categories.Select(x =>
{
return new CategoryModel()
{
Name = x.Name,
Id = x.ID,
BreadCrumb = GetCategoryBreadCrumb(x, categories),
numberOfChild = categories.Where(p => p.ParentID == x.ID).Count(),
};
}).ToList(); ;
var selectList = new List<SelectListItem>();
foreach (var c in categories)
selectList.Add(new SelectListItem()
{
Value = c.ID.ToString(),
Text = GetCategoryBreadCrumb(c, categories),
Selected = true
});
categoryModel.AvailableCategories = selectList;
if (ModelState.IsValid)
{
res = db.InsertCategory(categoryModel.Name, categoryModel.SelectedCategoryId, categoryModel.Image, true,categoryModel.MetaTitle, categoryModel.SeoKeywords, categoryModel.SeoDescription, categoryModel.DisplayOrders, categoryModel.ShowOnHomePage, categoryModel.Description, categoryModel.IsVideo, categoryModel.LinkName, categoryModel.Images, categoryModel.SortDescription,false);
if (res > 0)
{
res = db.InsertCategoryImages(res, categoryModel.Images);
categoryModel.msg = "Page Has Been Inserted Successfully.";
TempData["message"] = categoryModel.msg;
return RedirectToAction("Index");
}
else
{
return View("postPage", categoryModel); ;
}
}
else
{
return View("postPage", categoryModel); ;
}
}
else
{
return View("postPage", categoryModel);
}
}
catch
{
return View("~/Views/Shared/Error.cshtml");
}
}
public ActionResult Edit(int Id)
{
try
{
if (Convert.ToBoolean(Session["ValidateLogOn"]) != true)
return RedirectToAction("Index", "LogOn");
CategoryBL db = new CategoryBL();
var model = new CategoryModel();
model.Choice = "Save";
model.selectedPricing = new int[0];
model.Active = false;
if (Id > 0)
{
var c1 = db.getcategoryById(Id);
model.Active = true;
model.Id = c1.ID;
model.Name = c1.Name;
model.SelectedCategoryId = c1.ParentID;
model.MetaTitle = c1.meta_title;
model.SeoKeywords = c1.meta_keywords;
model.SeoDescription = c1.seo_description;
model.OfferLabel = c1.Offer_Label;
model.WantedLabel = c1.Wanted_Label;
model.Description = c1.Description;
model.ShowOnHomePage = c1.ShowOnHomePage != null ? c1.ShowOnHomePage.Value : false;
model.IsVideo = c1.IsProduct != null ? c1.IsProduct.Value : false;
model.LinkName = c1.LinkName;
model.SortDescription = c1.SortDescription;
model.DisplayOrders = c1.DisplayOrders.Value > 0 ? c1.DisplayOrders.Value : 0;
//model.Images = c1.CategoryImage;
model.Choice = "Update";
}
model.ParentCategories = new List<SelectListItem> { new SelectListItem { Text = "[None]", Value = "0" } };
var categories = db.GetCategoryList().Where(x => x.IsMarketing == false).ToList();
model.AllCategory = categories.ToList();
categories.Insert(0, new Category { Name = "[None]", ID = 0 });
model.ListCategoryModel = categories.Select(x =>
{
return new CategoryModel()
{
Name = x.Name,
Id = x.ID,
BreadCrumb = GetCategoryBreadCrumb(x, categories),
numberOfChild = categories.Where(p => p.ParentID == x.ID).Count(),
};
}).ToList(); ;
var selectList = new List<SelectListItem>();
foreach (var c in categories)
selectList.Add(new SelectListItem()
{
Value = c.ID.ToString(),
Text = GetCategoryBreadCrumb(c, categories),
Selected = true
});
model.AvailableCategories = selectList;
var categoriesImage = db.GetCategoryImage(Id).ToList();
model.CategoryImageList = categoriesImage.Select(x =>
{
return new CategoryImageModel()
{
Id = x.ID,
Title = x.Title,
catImages = x.ImageName,
ImageUrl = x.ImageName == null ? Url.Content("~/Content/images/no_image.jpg") : Url.Content("~/Content/CatagoryImage/") + x.ImageName
};
}).ToList(); ;
foreach (var i in model.CategoryImageList)
{
if (!string.IsNullOrEmpty(model.Images))
model.Images = model.Images + "~" + i.catImages;
else
model.Images = i.catImages;
}
return View("~/Areas/Admin/Views/AdminPage/Edit.cshtml", model);
}
catch (Exception ex)
{
throw ex;
}
}
[ValidateInput(false)]
[HttpPost]
public ActionResult Edit(CategoryModel categoryModel, FormCollection collection)
{
try
{
CategoryBL db = new CategoryBL();
Session["levelError"] = null;
Session["rowsEffected"] = null;
Session["msetype"] = null;
int res = 0;
int level = 0;
if (ModelState.IsValid)
{
db.DeleteCatagoryImage(categoryModel.Id, "");
res = db.UpdateCategory(categoryModel.Id, categoryModel.Name, categoryModel.SelectedCategoryId, true, categoryModel.MetaTitle,categoryModel.SeoKeywords, categoryModel.SeoDescription, categoryModel.ShowOnHomePage, categoryModel.Description, categoryModel.IsVideo, categoryModel.LinkName, categoryModel.Images, categoryModel.SortDescription, categoryModel.DisplayOrders);
if(res>0)
{
categoryModel.msg = "Page Has Been Updated Successfully.";
TempData["message"] = categoryModel.msg;
}
if (res > 0)
{
res = db.InsertCategoryImages(res, categoryModel.Images);
if (!string.IsNullOrEmpty(categoryModel.RemoveImgs))
{
string[] data = categoryModel.RemoveImgs.Split('~');
foreach (var item in data)
{
if (!string.IsNullOrEmpty(item))
{
var deleteimg = db.DeleteCatagoryImage(categoryModel.Id, item);
string path = Server.MapPath("~/Content/CatagoryImage/" + item);
FileInfo file1 = new FileInfo(path);
if (file1.Exists)//check file exsit or not
{
file1.Delete();
}
}
}
}
return RedirectToAction("Index");
}
else
{
return View("~/Areas/Admin/Views/AdminPage/Edit.cshtml", categoryModel); ;
}
}
else
{
return View("~/Areas/Admin/Views/AdminPage/Edit.cshtml", categoryModel); ;
}
}
catch
{
return View(categoryModel);
}
}
//public ActionResult UploadAsync()
//{
// try
// {
// List<string> imgNames;
// if (Session["images"] == null)
// {
// imgNames = new List<string>();
// }
// else
// {
// imgNames = (List<string>)Session["images"];
// }
// string name = string.Empty;
// if (Request.Files.Count > 0)
// {
// var file = Request.Files[0];
// Random rnd = new Random();
// name = rnd.Next(111, 9999).ToString() + "_" + System.IO.Path.GetFileName(file.FileName);
// imgNames.Add(name);
// string fullPath = Path.Combine(Server.MapPath("~/Content/CatagoryImage"), name);
// file.SaveAs(fullPath);
// Session["images"] = imgNames;
// }
// return Json(name, JsonRequestBehavior.AllowGet);
// }
// catch
// {
// return View("~/Views/Shared/Error.cshtml");
// }
//}
public ActionResult Delete(int Id)
{
if (Convert.ToBoolean(Session["ValidateLogOn"]) != true)
return RedirectToAction("Index", "LogOn");
CategoryBL db = new CategoryBL();
var c1 = db.getcategoryById(Id);
if (c1 == null)
return RedirectToAction("../Index");
// return RedirectToAction("Index", new { Id = 0 });
int res = 0;
CategoryModel model = new CategoryModel();
using (CategoryBL obj = new CategoryBL())
{
res = db.DeleteCategory(Id);
var categories = db.GetCategoryList().Where(x => x.IsMarketing == false).ToList();
var selectList = new List<SelectListItem>();
foreach (var c in categories)
selectList.Add(new SelectListItem()
{
Value = c.ID.ToString(),
Text = GetCategoryBreadCrumb(c, categories),
Selected = true
});
model.AvailableCategories = selectList;
}
model.pageAvailableCategories = model.AvailableCategories.ToPagedList(1, pageSize);
model.msg = "Page Has Been Deleted Successfully.";
TempData["Adminmessage"] = model.msg;
return RedirectToAction("Index");
}
#region Merchant Image
public ActionResult UploadAsync()
{
try
{
List<string> imgNames;
if (Session["images"] == null)
{
imgNames = new List<string>();
}
else
{
imgNames = (List<string>)Session["images"];
}
string name = string.Empty;
if (Request.Files.Count > 0)
{
var file = Request.Files[0];
Random rnd = new Random();
name = rnd.Next(111, 9999).ToString() + "_" + System.IO.Path.GetFileName(file.FileName);
imgNames.Add(name);
string fullPath = Path.Combine(Server.MapPath("~/Content/CatagoryImage"), name);
file.SaveAs(fullPath);
Session["images"] = imgNames;
}
return Json(name, JsonRequestBehavior.AllowGet);
}
catch
{
return View("~/Views/Shared/Error.cshtml");
}
}
public ActionResult DeleteImage(int Id)
{
Boolean flag = false;
int res = objImagesBL.DeleteImage(Id);
if (res > 0)
flag = true;
return Json(flag, JsonRequestBehavior.AllowGet);
}
public ActionResult UploadedImages()
{
var appData = Server.MapPath("~/Content/CatagoryImage/");
CategoryImageModel model = new CategoryImageModel();
var images = Directory.GetFiles(appData).Select(x => new CategoryImageModel
{
Url = Url.Content("~/Content/CatagoryImage/" + Path.GetFileName(x))
});
model.CategoryImageList = images.ToList();
return View("~/Areas/Admin/Views/AdminPage/UploadedImages.cshtml",images);
}
#endregion
}
}
UserDl objuser = new UserDl();
public int AbacusUser(string fullnamne, string email, string password, string mobile, Boolean status)
{
try
{
return objuser.AbacusUser(fullnamne, email, password, mobile, status);
}
catch(Exception ex)
{
throw ex;
}
}
public int AbacusUser(string fullnamne, string email, string password, string mobile, Boolean status)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
int res = 0;
try
{
Abacu objAbacu = new Abacu();
objAbacu.FullName = fullnamne;
objAbacu.Email = email;
objAbacu.Password = password;
objAbacu.MobileNo = mobile;
objAbacu.Status = status;
db.Abacus.Add(objAbacu);
db.SaveChanges();
res = objAbacu.ID;
}
catch (Exception ex)
{
throw ex;
}
return res;
}
}
//category
 
public class CategoryDL : CoreEntity
{
public Category getcategoryById(int Id)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
var c1 = db.Categories.Where(x => x.ID == Id).FirstOrDefault();
return c1;
}
}
public Category getcategorybyName(string name)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
var c1 = db.Categories.Where(x => x.Name.Trim().ToLower().Contains(name.Trim().ToLower())).FirstOrDefault();
return c1;
}
}
public List<Category> GetCategoryList(bool hideInactive = false)
{
try
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
var unsortedCat = db.Categories.ToList();
if (hideInactive)
unsortedCat = unsortedCat.Where(x => x.Active == true).ToList();
var sortedCat = SortCategoriesForTree(unsortedCat, 0);
return sortedCat;
}
}
catch (System.Data.Entity.Validation.DbEntityValidationException e)
{
string validationErrors = "DbEntityValidationException ValidationErrors: ";
foreach (var k in e.EntityValidationErrors)
{
foreach (var e1 in k.ValidationErrors)
{
validationErrors += string.Format("{0} - {1}; ", e1.PropertyName, e1.ErrorMessage);
}
}
throw new Exception(validationErrors, e);
}
}
public List<Category> SortCategoriesForTree(List<Category> source, int parentId)
{
var result = new List<Category>();
var temp = source.ToList().FindAll(c => c.ParentID == parentId);
foreach (var cat in temp)
{
result.Add(cat);
result.AddRange(SortCategoriesForTree(source, cat.ID));
}
return result;
}
public int InsertCategory(string Name, int ParentID, string Image, bool IsActive, string MetaTitle, string seoKey, string seoDescription, int displayorders, bool ShowOnHomePage, string description, bool IsProduct, string LinkName, string Images, string sortDescription, bool ismarketing)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
int res = 0;
try
{
Category objcategory = new Category();
objcategory.ParentID = ParentID;
objcategory.Name = Name;
objcategory.CategoryImage = Image;
objcategory.Active = IsActive;
objcategory.meta_title = MetaTitle;
objcategory.meta_keywords = seoKey;
objcategory.seo_description = seoDescription;
objcategory.DisplayOrders = displayorders;
objcategory.ShowOnHomePage = ShowOnHomePage;
objcategory.Description = description;
objcategory.IsProduct = IsProduct;
objcategory.LinkName = LinkName;
objcategory.CategoryImage = Image;
objcategory.SortDescription = sortDescription;
objcategory.IsMarketing = ismarketing;
db.Categories.Add(objcategory);
db.SaveChanges();
res = objcategory.ID;
}
catch (DbEntityValidationException ex)
{
foreach (var eve in ex.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
return res;
}
}
public int InsertCategoryImages(int ParentID, string Images)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
int res = 0;
try
{
CategoryImage objcategory = new CategoryImage();
objcategory.CatID = ParentID;
objcategory.Title = Images;
objcategory.ImageName = Images;
db.CategoryImages.Add(objcategory);
db.SaveChanges();
res = objcategory.ID;
}
catch (Exception ex)
{
throw ex;
}
return res;
}
}
public int UpdateCategory(int ID, string Name, int ParentID, bool IsActive, string MetaTitle, string seoKey, string seoDescription, bool ShowOnHomePage, string description, bool IsProduct, string LinkName, string Images, string sortDescription, int displayOrders)
{
using (ksoft_WebGuideEntities objOriginextEntities = new ksoft_WebGuideEntities())
{
int res = 0;
try
{
Category resultCat = objOriginextEntities.Categories.Where(p => p.ID == ID).Single();
if (resultCat != null)
{
resultCat.Name = Name;
resultCat.ParentID = ParentID;
resultCat.Active = IsActive;
resultCat.meta_title = MetaTitle;
resultCat.seo_description = seoDescription;
resultCat.meta_keywords = seoKey;
resultCat.CategoryImage = Images;
resultCat.ShowOnHomePage = ShowOnHomePage;
resultCat.Description = description;
resultCat.IsProduct = IsProduct;
resultCat.LinkName = LinkName;
resultCat.SortDescription = sortDescription;
resultCat.DisplayOrders = displayOrders;
}
objOriginextEntities.SaveChanges();
res = resultCat.ID;
}
catch (Exception ex)
{
throw ex;
}
return res;
}
}
public int DeleteCategory(int ID)
{
int res = 0;
DeleteCatagoryImage(ID, "");
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
var ChildCategories = (from d in db.Categories where d.ParentID == ID select d).ToList();
if (ChildCategories != null)
{
foreach (var c in ChildCategories)
{
DeleteCatagoryImage(c.ID, "");
db.Categories.Remove(c);
db.SaveChanges();
}
}
try
{
Category resultTemplate = db.Categories.Where(p => p.ID == ID).Single();
db.Categories.Attach(resultTemplate);
db.Categories.Remove(resultTemplate);
db.SaveChanges();
res = 1;
}
catch (Exception ex) { }
return res;
}
}
/// <summary>
/// get Dynamic field by Id
/// </summary>
/// <param name="Id">Id</param>
/// <returns>Single Filed</returns>
public CategoryField getFieldById(int Id)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
return (db.CategoryFields.Where(x => x.ID == Id)).SingleOrDefault();
}
}
public Category getCatById(int Id)
{
ksoft_WebGuideEntities db = new ksoft_WebGuideEntities();
return (db.Categories.Where(x => x.ID == Id)).SingleOrDefault();
}
/// <summary>
/// Get List fo dynamic fields for a category
/// </summary>
/// <param name="categoryId">CategoryId</param>
/// <returns>List of dynamic controls</returns>
public List<CategoryField> getFieldsByCategoryId(int categoryId)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
return (db.CategoryFields.Where(x => x.CategoryID == categoryId)).ToList();
}
}
public List<sp_getOpionalFieldValuesByFieldCategoryId_Result> getOpionalFieldValuesByFieldCategoryId(int fieldCategoryId)
{
using (var db = new ksoft_WebGuideEntities())
{
return db.sp_getOpionalFieldValuesByFieldCategoryId(fieldCategoryId).ToList();
}
}
#region rajib
#region DynamicFields
//public int InsertDynamicFields(int categoryId, string selectedControl, string fieldLabel, bool isRequired, string[] OptionListValues)
/// <summary>
/// Insert dynamic controls associated with category
/// </summary>
/// <param name="categoryId">category id</param>
/// <param name="selectedControl">control type</param>
/// <param name="fieldLabel">label to display</param>
/// <param name="isRequired">is mandatory column</param>
/// <param name="OptionListValues">option list for drop down,check boxes and redio buttons</param>
/// <returns>id of inserted row</returns>
public int InsertDynamicFields(int categoryId, string selectedControl, string fieldLabel, bool isRequired, bool isActive, bool IsShowOnDetailsPage, string hdnOptionValues, int displayorder)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
int res = 0;
try
{
var entity = new CategoryField()
{
CategoryID = categoryId,
ControlToDisplay = selectedControl,
FieldLabel = fieldLabel,
RequiredValidation = isRequired,
IsActive=isActive,
IsShowOnDetailsPage=IsShowOnDetailsPage,
DisplayOrder = displayorder
};
db.CategoryFields.Add(entity);
db.SaveChanges();
if (!string.IsNullOrEmpty(hdnOptionValues))
{
string[] OptionValues = hdnOptionValues.Split('~');
for (int i = 0; i < OptionValues.Count(); i++)
{
if (OptionValues[i] != "")
{
var options = new CategoryFieldListControlValue()
{
CategoryFieldID = entity.ID,
DisplayOrder = 0,
OptionalValue = OptionValues[i]
};
db.CategoryFieldListControlValues.Add(options);
db.SaveChanges();
}
}
}
res = entity.ID;
}
catch (Exception ex)
{
throw ex;
}
return res;
}
}
/// <summary>
/// Update dynamic controls associated with category
/// </summary>
/// <param name="categoryId">id</param>
/// <param name="selectedControl">control type</param>
/// <param name="fieldLabel">label to display</param>
/// <param name="isRequired">is mandatory column</param>
/// <param name="OptionListValues">option list for drop down,check boxes and redio buttons</param>
/// <returns>id of updated row</returns>
public int UpdateDynamicFields(int Id, string selectedControl, string fieldLabel, bool isRequired, bool isActive, bool IsShowOnDetailsPage, string hdnOptionValues, int displayorder)
{
int res = 0;
using (ksoft_WebGuideEntities objOriginextEntities = new ksoft_WebGuideEntities())
{
try
{
var DynamicField = objOriginextEntities.CategoryFields.Where(x => x.ID == Id).SingleOrDefault();
if (DynamicField == null)
throw new ArgumentNullException("Id");
DynamicField.FieldLabel = fieldLabel;
DynamicField.RequiredValidation = isRequired;
DynamicField.ControlToDisplay = selectedControl;
DynamicField.IsActive=isActive;
DynamicField.IsShowOnDetailsPage=IsShowOnDetailsPage;
DynamicField.DisplayOrder = displayorder;
objOriginextEntities.SaveChanges();
if (!string.IsNullOrEmpty(hdnOptionValues))
{
string[] OptionValues = hdnOptionValues.Split('~');
for (int i = 0; i < OptionValues.Count(); i++)
{
if (OptionValues[i] != "")
{
string[] Options = OptionValues[i].Split(':');
if (Convert.ToInt32(Options[0]) > 0)
{
int fieldid=Convert.ToInt32(Options[0]);
var field = objksoft_WebGuideEntities.CategoryFieldListControlValues.Where(x => x.ID == fieldid).First();
if (field != null)
{
if (Options[1] != "")
{
field.OptionalValue = Options[1];
objksoft_WebGuideEntities.SaveChanges();
}
}
}
else
{
var options = new CategoryFieldListControlValue()
{
CategoryFieldID = Id,
DisplayOrder = 0,
OptionalValue = Options[1]
};
objOriginextEntities.CategoryFieldListControlValues.Add(options);
objOriginextEntities.SaveChanges();
}
}
}
}
res = 1;
}
catch (Exception ex)
{
res = 0;
throw ex;
}
return res;
}
}
/// <summary>
/// Gets all Categories
/// </summary>
/// <param name="parentId">if parentId is 0,it will take all parent catogories else it will take child of parentId</param>
/// <returns>Category list</returns>
public List<sp_getAllCategories_Result> getAllCategories(int parentId = 0)
{
try
{
using (ksoft_WebGuideEntities objEntity = new ksoft_WebGuideEntities())
{
return objEntity.sp_getAllCategories(parentId).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// Get Values of optional fields like checkboxlist,dropdownlist,readiobuttonlist
/// </summary>
/// <param name="categoryId">int CategoryId</param>
/// <returns>List of optional values</returns>
public List<sp_getOpionalFieldValuesByCategoryId_Result> getOpionalFieldValuesByCategoryId(int categoryId)
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
return db.sp_getOpionalFieldValuesByCategoryId(categoryId).ToList();
}
}
/// <summary>
/// Get category and its fields
/// </summary>
/// <param name="categoryId">CategoryId</param>
/// <returns>List of category and fields</returns>
public List<sp_getCategoryById_Result> getCategoryById(int categoryId)
{
using (var db = new ksoft_WebGuideEntities())
{
return db.sp_getCategoryById(categoryId).ToList();
}
}
public int DeleteField(int Id)
{
int res = 0;
var f = objksoft_WebGuideEntities.CategoryFields.Where(x => x.ID == Id).SingleOrDefault();
try
{
objksoft_WebGuideEntities.CategoryFields.Remove(f);
objksoft_WebGuideEntities.SaveChanges();
res = 1;
}
catch (Exception ex) { }
return res;
}
public int DeleteDynamicFieldValue(int Id)
{
int res = 0;
var f = objksoft_WebGuideEntities.CategoryFieldListControlValues.Where(x => x.ID == Id).SingleOrDefault();
try
{
objksoft_WebGuideEntities.CategoryFieldListControlValues.Remove(f);
objksoft_WebGuideEntities.SaveChanges();
res = 1;
}
catch (Exception ex) { }
return res;
}
public int UpdateCategoryFieldValue(int Id, string Value, int CategoryId)
{
int res = 0;
try
{
if (Id > 0)
{
var field = objksoft_WebGuideEntities.CategoryFieldListControlValues.Where(x => x.ID == Id).SingleOrDefault();
field.OptionalValue = Value;
}
else
{
var options = new CategoryFieldListControlValue()
{
CategoryFieldID = CategoryId,
DisplayOrder = 0,
OptionalValue = Value
};
objksoft_WebGuideEntities.CategoryFieldListControlValues.Add(options);
}
objksoft_WebGuideEntities.SaveChanges();
res = 1;
}
catch (Exception ex) { }
return res;
}
#endregion
#endregion
public List<sp_GetAllCategoryFieldValueDetails_Result> GetAllCategoryFieldValueDetails()
{
using (var db = new ksoft_WebGuideEntities())
{
return db.sp_GetAllCategoryFieldValueDetails().ToList();
}
}
public List<sp_GetShowOnHomePageParentCategory_Result> GetShowOnHomePageParentCategory()
{
using (var db = new ksoft_WebGuideEntities())
{
return db.sp_GetShowOnHomePageParentCategory().ToList();
}
}
public List<CategoryImage> GetCategoryImage(int catid)
{
using (var db = new ksoft_WebGuideEntities())
{
if(catid>0)
return db.CategoryImages.Where(x=>x.CatID==catid).ToList();
else
return db.CategoryImages.ToList();
}
}
public int DeleteCatagoryImage(int CatId, string image)
{
int res = 0;
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
if (image != null && image!="")
{
var CategoriesImages = (from d in db.CategoryImages where d.CatID == CatId & d.ImageName==image select d).ToList();
if (CategoriesImages != null)
{
foreach (var c in CategoriesImages)
{
db.CategoryImages.Remove(c);
db.SaveChanges();
res = 1;
}
}
}
else
{
var CategoriesImages = (from d in db.CategoryImages where d.CatID == CatId select d).ToList();
if (CategoriesImages != null)
{
foreach (var c in CategoriesImages)
{
db.CategoryImages.Remove(c);
db.SaveChanges();
res = 1;
}
}
}
return res;
}
}
public List<ProductCategory> GetProductCategoryDL()
{
using (var db = new ksoft_WebGuideEntities())
{
return db.ProductCategories.Where(x => x.ParentID == 0 &&x.Active==true).ToList();
}
}
//public List<usp_ParentChildCombinbationcategory> GetProductCategoryDL()
public List<usp_ParentChildCombinbationcategory_Result> ParentChildCombinbationcategory()
{
try
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
return db.usp_ParentChildCombinbationcategory().ToList();
}
}
catch(Exception ex)
{
throw ex;
}
}
//public List<sp_prntchildcombinationlastname_Result> beginlastname()
//{
// try
// {
// using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
// {
// return db.usp_prntchildcombinationlastname().ToList();
// }
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
//public List<sp_tes> begintest()
//{
// try
// {
// using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
// {
// return db.sp_testing().ToList();
// }
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
public List<sp_getnameandparentid_Result> getnamendprntid(int parentid)
{
try
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
return db.sp_getnameandparentid(parentid).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
//public List<sp_Getparentid_Result> getnamendprntid(string parentname)
//{
// try
// {
// using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
// {
// return db.sp_Getparentid(parentname).ToList();
// }
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
public List<sp_CallBreadCrumb_Result> CallBreadCrumb(int id)
{
try
{
using (ksoft_WebGuideEntities db = new ksoft_WebGuideEntities())
{
return db.sp_CallBreadCrumb(id).ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}
}
 
public class AdminBL
{
AdminDL db = new AdminDL();
public up_adminlogin_Result AdminLogin(string username, string pwd)
{
return db.AdminLogin(username, pwd);
}
public static int SaveUpdateAdminLogin(int Id, string UserName, string Pwd)
{
int result = 0;
try
{
result = AdminDL.SaveUpdateAdminLogin(Id, UserName, Pwd);
}
catch (Exception ex)
{
}
return result;
}
}
 
 
 
 

Answers (1)