public void InsertOrUpdate(tCategory user) { if (user.InitialLetter.Length > 1) { user.InitialLetter = user.InitialLetter.Substring(0, 1); } if (user.IDCategory == default(int)) { // New entity context.tCategories.InsertOnSubmit(user); } else { // Existing entity //context.USERs.Attach(user); //context.Entry(user).State = EntityState.Modified; tCategory userToUpdate = Find(user.IDCategory); if (userToUpdate != null && userToUpdate.IDCategory > 0) { userToUpdate.IDCategoryType = user.IDCategoryType; userToUpdate.IDGroup = user.IDGroup; userToUpdate.InitialLetter = user.InitialLetter; userToUpdate.Slug = user.Slug; userToUpdate.Sort = user.Sort; userToUpdate.Name = user.Name; userToUpdate.DisplayFlag = user.DisplayFlag; } } context.SubmitChanges(); }
public ActionResult Index() { if (MembershipHelper.CurrentCity == null || MembershipHelper.CurrentCity.IDCategory == 0) { tCategory cat = _categoryRepository.GetListByIDCategoryType((int)Enums.enmCategoryTypes.City). FirstOrDefault(); if (cat == null) { cat = new tCategory() { Name = "City Not Found", IDCategory = 0 } } ; MembershipHelper.CurrentCity = cat; } tDeal currentDeal = _dealRepository.GetLatestDeal(MembershipHelper.CurrentCity.IDCategory); ViewBag.LeftTSStr = tDealUtils.GetLeftTSStrForDeal(currentDeal); if (currentDeal == null) { currentDeal = new tDeal(); } if (MembershipHelper.CurrentCity != null && currentDeal != null) { ViewBag.DealsBySameCategory = _dealRepository.GetListByIDCategory(currentDeal.IDDealCategory).Take(6).OrderByDescending(t => t.DateAdded).ToList(); } else { ViewBag.DealsBySameCategory = new List <tDeal>(); } return(View(currentDeal)); }
// // GET: /Category/Edit/5 public ActionResult Edit(int id) { List <tGroup> groupData = _groupRepository.All.ToList(); ViewBag.groupData = groupData; tCategory currentCat = _categoryRepository.Find(id); return(View(currentCat)); }
protected void btnSave_Click(object sender, EventArgs e) { if (cl.checkRole(Session["userid_hcc"].ToString(), codeModule, 1)) { if (txtName.Text.Trim().Equals("")) { Mess("Nhập tên lĩnh vực", ""); } else { try { string filename = DateTime.Now.ToString("ddMMyyyyhhmmss"), file_ex1 = "", file_ex2 = ""; tCategory cat = new tCategory(); if (fuImage.HasFile) { file_ex1 = fuImage.FileName.Trim(); file_ex1 = file_ex1.Substring(file_ex1.LastIndexOf('.')); cat.Image = "/wp-content/uploads/category/" + filename + file_ex1; } cat.Content = txtContent.Text.Trim(); cat.Caption = txtName.Text.Trim(); if (fuIcon.HasFile) { file_ex2 = fuImage.FileName.Trim(); file_ex2 = file_ex2.Substring(file_ex2.LastIndexOf('.')); cat.Icon = "/wp-content/uploads/category/icon_" + filename + file_ex2; } cat.IsActive = ckActive.Checked; cat.CreateAt = DateTime.Now; db.tCategories.InsertOnSubmit(cat); db.SubmitChanges(); if (fuImage.HasFile) { fuImage.SaveAs(Server.MapPath("/wp-content/uploads/category/" + filename + file_ex1)); } if (fuIcon.HasFile) { fuIcon.SaveAs(Server.MapPath("/wp-content/uploads/category/icon_" + filename + file_ex2)); } ResetControl(); LoadGrid(); Mess("Lưu thành công", ""); } catch (Exception ax) { Mess(ax.Message, ""); } } } else { Mess("Bạn không có quyền sử dụng chức năng này", "/adhome"); } }
public void Delete(int id) { tCategory user = Find(id); if (user != null && user.IDCategory > 0) { context.tCategories.DeleteOnSubmit(user); } context.SubmitChanges(); }
/// <summary> /// 添加分类 /// </summary> /// <param name="categoryName"></param> /// <param name="parentid"></param> /// <returns></returns> public ActionResult AddCategory(string categoryName, int parentid) { var parentCategory = db.tCategories.FirstOrDefault(m => m.ParentId == parentid); if (parentCategory != null) { tCategory category = new tCategory() { CategoryName = categoryName, ParentId = parentid, CategoryPath = parentCategory.CategoryPath + parentid }; db.tCategories.AddObject(category); db.SaveChanges(); } return(RedirectToAction("Category")); }
private void CheckCategory(string category) { var tCategory = new tCategory(); tCategory = categoryRepository.Get(m => m.Name == category); if (tCategory != null) { tNovel.CategoryId = tCategory.CategoryId; } else { var newCategory = new tCategory { Name = category }; categoryRepository.Create(newCategory); tNovel.CategoryId = categoryRepository.Get(m => m.Name == category).CategoryId; } }
public JsonResult EditAjax(tCategory city) { if (ModelState.IsValid) { _categoryRepository.InsertOrUpdate(city); return(Json(new { objectAddedName = city.Name, valid = true, Message = "Category was updated Succesfully" })); } else { return(Json(new { objectAddedName = "", valid = false, Message = "Fill All Fields please" })); } }
//[Authorize(Roles="Admin")] //[ChildActionOnly] //public ActionResult DealCities(tDeal deal) //{ // return PartialView(deal); //} #endregion #region UserSide public ActionResult DealsByCategory(int?IDCity) { tCategory cat; if (IDCity == null) { IDCity = 1; } cat = _categoryRepository.Find((int)IDCity); if (cat == null) { cat = new tCategory(); } List <tDeal> deals = _dealRepository.GetListByCity((int)IDCity).OrderByDescending(t => t.DateAdded).ToList(); tDealFrontEndModel model = new tDealFrontEndModel(); model.currentCat = cat; model.currentDeals = deals; return(View(model)); }
public ActionResult CitySelector() { tCategory cat = _categoryRepository.Find(MembershipHelper.CurrentCity.IDCategory); List <tCategory> cats = _categoryRepository.GetListByIDCategoryType((int)Enums.enmCategoryTypes.City); ViewBag.catData = cats; if (cat == null) { cat = cats.FirstOrDefault(); } if (cat == null) { cat = new tCategory() { Name = "City Not Found", IDCategory = 0 } } ; return(PartialView(cat)); }
partial void DeletetCategory(tCategory instance);
partial void UpdatetCategory(tCategory instance);
partial void InserttCategory(tCategory instance);
public ActionResult Select(tCategory selectedCat) { MembershipHelper.CurrentCity = selectedCat; return(RedirectToAction("Index", "Home")); }
public ActionResult PartialFrontEndTopMenu() { tCategory cat = MembershipHelper.CurrentCity; return(PartialView(cat)); }