//public string Add(CategoryDummay category) //{ // try // { // if (category != null) // { // if (!IsDuplicate(string.Empty, category.CategoryDesc)) // { // string fname = HttpContext.Server.MapPath("Uploads\\" + category.Attachment.FileName); // category.Attachment.SaveAs(fname); // category.CategoryID = Guid.NewGuid().ToString(); // category.DealerID = CommonConstant.GetFieldValueString(Session[CommonConstant.SessionUserID]); // category.UpdateDate = DateTime.Now; // category.CreateDate = DateTime.Now; // //db.Categories.Add(category); // db.SaveChanges(); // return "Success|" + category.CategoryID.ToString(); // } // else // { // return "Failed|This category name is already in used."; // } // } // } // catch (Exception ex) // { // } // return "Failed|Add new category failed"; //} public string Add(CategoryDummay category) { try { if (category != null) { if (!IsDuplicate(string.Empty, category.CategoryName)) { Category cate = new Category(); if (category.Attachment != null) { cate.ImgPath = cate.CategoryID + "\\" + category.Attachment.FileName; try { //string fname = HttpContext.Server.MapPath("Uploads\\" + cate.CategoryID + "\\" + category.Attachment.FileName); string fname = HttpContext.Server.MapPath("Uploads\\" + category.Attachment.FileName); //string fname = CommonConstant.GetSiteRoot() + "Uploads\\" + cate.CategoryID + "\\" + category.Attachment.FileName; category.Attachment.SaveAs(fname); } catch (Exception err) { } } cate.CategoryID = Guid.NewGuid().ToString(); cate.CategoryName = category.CategoryName; cate.DealerID = CommonConstant.GetFieldValueString(Session[CommonConstant.SessionUserID]); cate.UpdateDate = DateTime.Now; cate.CreateDate = DateTime.Now; cate.ParentID = category.ParentID; db.Categories.Add(cate); db.SaveChanges(); return "Success|" + cate.CategoryID.ToString(); } else { return "Failed|This category name is already in used."; } } } catch (Exception ex) { LogFile.writeLogFile(DateTime.Now, "CategoryController", ex.ToString()); } return "Failed|Add new category failed"; }
public JsonResult GetCategoryList() { try { string strUserID = CommonConstant.GetFieldValueString(Session[CommonConstant.SessionUserID]); var CategoryList = db.Categories.Where(m => m.DealerID == strUserID).ToList(); Category cate = new Category(); cate.CategoryID = "0"; cate.CategoryName = "Root"; cate.DealerID = strUserID; cate.ParentID = null; CategoryList.Add(cate); return Json(CategoryList, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogFile.writeLogFile(DateTime.Now, "ContentManagementController", ex.ToString()); string str = ex.Message.ToString(); } return null; }
public string Update(Category category) { try { if (category != null) { if (!IsDuplicate(category.CategoryID, category.CategoryName)) { Category cate = db.Categories.Find(category.CategoryID); cate.CategoryName = category.CategoryName; cate.ImgPath = category.ImgPath; cate.UpdateDate = DateTime.Now; db.Entry(cate).State = EntityState.Modified; db.SaveChanges(); return "Success"; } else { return "This category name is already in used."; } } } catch (Exception ex) { LogFile.writeLogFile(DateTime.Now, "CategoryController", ex.ToString()); } return "Update failed"; }
public JsonResult GetCategoryTrees() { try { string strUserID = CommonConstant.GetFieldValueString(Session[CommonConstant.SessionUserID]); var results = db.Categories.Where(m => m.DealerID == strUserID).OrderBy(m => m.CategoryName).ToList(); Category cate = new Category(); cate.CategoryID = "0"; cate.CategoryName = "Root"; cate.DealerID = strUserID; cate.ParentID = null; results.Add(cate); return Json(results, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogFile.writeLogFile(DateTime.Now, "CategoryController", ex.ToString()); } return Json(null, JsonRequestBehavior.AllowGet); }