public static procategory GetCategoryById(int category_id) { using (var context = new WebsiteTTKEntities()) { var result = context.procategories.SingleOrDefault(b => b.category_id == category_id); if (result != null) { procategory item = new procategory(); item.category_id = result.category_id; item.category_name = result.category_name; item.category_description = result.category_description; item.category_images = result.category_images; item.category_url = result.category_url; item.create_date = result.create_date; item.parent_id = result.parent_id; item.is_publish = result.is_publish; item.is_menu = result.is_menu; item.is_label = result.is_label; item.is_collection = result.is_collection; item.store_id = result.store_id; return(item); } return(null); } }
private void ShowData() { using (var context = new WebsiteTTKEntities()) { string id = Request.QueryString["id"]; string table_name = Request.QueryString["table_name"]; if (table_name == "products") { int product_id = -1; Int32.TryParse(id, out product_id); if (product_id > 0) { IQueryable <product> qProductsTable = from t in context.products where t.product_id == product_id select t; product objPro = qProductsTable.FirstOrDefault(); if (objPro != null) { if (objPro.product_images != null) { Images_Data.InnerText = objPro.product_images; } else { Images_Data.InnerText = ""; } } } } else if (table_name == "categories") { int category_id = -1; Int32.TryParse(id, out category_id); if (category_id > 0) { IQueryable <procategory> qCategoriesTable = from t in context.procategories where t.category_id == category_id select t; procategory objCat = qCategoriesTable.FirstOrDefault(); if (objCat != null) { if (objCat.category_images != null) { Images_Data.InnerText = objCat.category_images; } else { Images_Data.InnerText = ""; } } } } string hostURL = Helper.GetHostURL(); Service_URL.InnerText = hostURL + "/admin/Services/UploadImageService.asmx"; Service_URL_Name.InnerText = "/Services/UploadImageService.asmx"; Host_URL.InnerText = hostURL; } }
protected void lbnSubmit_Click(object sender, EventArgs e) { if (fulImageUpload.HasFile) { using (var context = new WebsiteTTKEntities()) { string id = Request.QueryString["id"]; string table_name = Request.QueryString["table_name"]; if (table_name == "products") { int product_id = -1; Int32.TryParse(id, out product_id); if (product_id > 0) { IQueryable <product> qProductsTable = from t in context.products where t.product_id == product_id select t; product objPro = qProductsTable.FirstOrDefault(); if (objPro != null) { string subPath = "~/admin/img/" + product_id + "/"; List <KeyValuePair <string, object> > result = Helper.SaveFileFromUpload(subPath, fulImageUpload, new string[] { ".jpg", ".gif", ".png", ".jpeg" }); string message = result.First(kvp => kvp.Key == "message").Value.ToString(); string isSuccess = result.First(kvp => kvp.Key == "result").Value.ToString(); if (Boolean.Parse(isSuccess)) { string fileName = result.First(kvp => kvp.Key == "fileName").Value.ToString(); if (objPro.product_images != null) { objPro.product_images = objPro.product_images + ";admin/img/" + product_id + "/" + fileName; } else { objPro.product_images = "admin/img/" + product_id + "/" + fileName; } ProductHelper.UpdateProducts(new List <product> { objPro }, true); lblUploadResult.Text = "<br/>" + message; } else { lblUploadResult.Text = "<br/>" + message; } } else { lblUploadResult.Text = "<br/>Product id " + product_id + " doesn't exist!"; } } } else if (table_name == "categories") { int category_id = -1; Int32.TryParse(id, out category_id); if (category_id > 0) { IQueryable <procategory> qCategoriesTable = from t in context.procategories where t.category_id == category_id select t; procategory objCat = qCategoriesTable.FirstOrDefault(); if (objCat != null) { string subPath = "~/admin/img/cat_" + category_id + "/"; List <KeyValuePair <string, object> > result = Helper.SaveFileFromUpload(subPath, fulImageUpload, new string[] { ".jpg", ".gif", ".png", ".jpeg" }); string message = result.First(kvp => kvp.Key == "message").Value.ToString(); string isSuccess = result.First(kvp => kvp.Key == "result").Value.ToString(); if (Boolean.Parse(isSuccess)) { string fileName = result.First(kvp => kvp.Key == "fileName").Value.ToString(); if (objCat.category_images != null) { objCat.category_images = objCat.category_images + ";admin/img/cat_" + category_id + "/" + fileName; } else { objCat.category_images = "admin/img/cat_" + category_id + "/" + fileName; } CategoryHelper.UpdateCategories(new List <procategory> { objCat }, true); lblUploadResult.Text = "<br/>" + message; } else { lblUploadResult.Text = "<br/>" + message; } } else { lblUploadResult.Text = "<br/>Category id " + category_id + " doesn't exist!"; } } } } } ShowData(); }
protected void btnApplyAllChanges_Click(object sender, EventArgs e) { //Create category list from json posted from client List <procategory> categories = new List <procategory>(); var categoriesJson = Category_Data_To_Post_To_Server.Text; dynamic categoriesResponse = JsonConvert.DeserializeObject(categoriesJson); if (categoriesResponse.Count > 0) { List <object> categoryObjects = categoriesResponse.ToObject <List <object> >(); foreach (var obj in categoryObjects) { procategory item = new procategory(); int category_id = -1; Int32.TryParse(Helper.GetPropValue(obj + "", "category_id") + "", out category_id); item.category_id = category_id; item.category_name = Helper.GetPropValue(obj + "", "category_name") + ""; item.category_description = Helper.GetPropValue(obj + "", "category_description") + ""; item.category_url = Helper.GetPropValue(obj + "", "category_url") + ""; item.create_date = Helper.ConverToDateTime(Helper.GetPropValue(obj + "", "create_date") + ""); int parent_id = -1; Int32.TryParse(Helper.GetPropValue(obj + "", "parent_id") + "", out parent_id); item.parent_id = parent_id; bool is_publish = true; bool.TryParse(Helper.GetPropValue(obj + "", "is_publish") + "", out is_publish); item.is_publish = is_publish; bool is_menu = true; bool.TryParse(Helper.GetPropValue(obj + "", "is_menu") + "", out is_menu); item.is_menu = is_menu; bool is_label = true; bool.TryParse(Helper.GetPropValue(obj + "", "is_label") + "", out is_label); item.is_label = is_label; bool is_collection = true; bool.TryParse(Helper.GetPropValue(obj + "", "is_collection") + "", out is_collection); item.is_collection = is_collection; int store_id = -1; Int32.TryParse(Helper.GetPropValue(obj + "", "store_id") + "", out store_id); item.store_id = store_id; categories.Add(item); } } //Delete records from category //Get category ids from json posted from client var deletedIdsJson = txtDeletedIds.Text; dynamic deletedIdsResponse = JsonConvert.DeserializeObject(deletedIdsJson); if (deletedIdsResponse.Count > 0) { List <int> deletedIds = deletedIdsResponse.ToObject <List <int> >(); if (deletedIds.Count > 0) { foreach (var id in deletedIds) { var found = categories.Find(x => x.category_id == id); if (found != null) { categories.Remove(found); } } CategoryHelper.DeleteCategoryByIds(deletedIds); } } CategoryHelper.UpdateCategories(categories); PushDataToClient(); }