public ActionResult Create(WebInfoViewModel viewmodel) { try { var model = new WebInfo(); model.Logo = viewmodel.Logo; model.Email = viewmodel.Email; model.Phone = viewmodel.Phone; model.Address = viewmodel.Address; model.Facebook = viewmodel.Facebook; model.Youtube = viewmodel.Youtube; model.Zalo = viewmodel.Zalo; _db.WebInfos.Add(model); _db.SaveChanges(); Notification.set_flash("Lưu thành công!", "success"); ModelState.Clear(); return(View()); } catch (Exception ex) { Notification.set_flash("Thêm thất bại!", "warning"); throw ex; } }
public ActionResult Create(SlideViewModel viewmodel) { try { if (ModelState.IsValid) { var model = new Slide(); model.Img = viewmodel.Img; model.Status = viewmodel.Status; model.CreateDate = DateTime.Now; model.Deleted = false; model.CreateBy = 1; _db.Slides.Add(model); _db.SaveChanges(); Notification.set_flash("Lưu thành công!", "success"); ModelState.Clear(); } else { Notification.set_flash("Nhập đầy đủ thông tin!", "warning"); } return(View()); } catch (Exception ex) { Notification.set_flash("Thêm thất bại!", "warning"); throw ex; } }
public ActionResult Create(MenuViewModel viewmodel) { try { if (ModelState.IsValid) { var model = new Menu(); model.Name = viewmodel.Name; model.ParentId = viewmodel.ParentId; model.Status = viewmodel.Status; model.CreateDate = DateTime.Now; model.DisplayOrder = viewmodel.DisplayOrder; _db.Menus.Add(model); _db.SaveChanges(); Notification.set_flash("Lưu thành công!", "success"); ModelState.Clear(); } else { Notification.set_flash("Nhập đầy đủ thông tin!", "warning"); } htmlOption = ""; htmlOption = this.DropdownAdd(0); ViewBag.htmlOption = htmlOption; return(View()); } catch (Exception ex) { Notification.set_flash("Thêm thất bại!", "warning"); throw ex; } }
public JsonResult SavePermission(int roleId, List <string> listPermissions) { if (roleId == 0) { Notification.set_flash("Vui lòng chọn nhóm quyền!", "warning"); return(Json(false, JsonRequestBehavior.AllowGet)); } else { foreach (var item in db.Permissions.Where(x => x.RoleId == roleId).ToList()) { db.Permissions.Remove(item); } foreach (var item in listPermissions.Distinct()) { string[] arrListStr = item.Split('_'); var model = new Permission(); model.RoleId = roleId; model.CommandId = arrListStr[arrListStr.Length - 1]; model.FunctionId = item.Substring(0, item.Length - arrListStr[arrListStr.Length - 1].Length - 1); db.Permissions.Add(model); } Notification.set_flash("Cập nhật quyền thành công!", "success"); db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); } }
public ActionResult Create(RoleViewModel viewmodel) { try { var model = new Role(); model.Name = viewmodel.Name; _db.Roles.Add(model); _db.SaveChanges(); Notification.set_flash("Lưu thành công!", "success"); ModelState.Clear(); return(View()); } catch (Exception ex) { Notification.set_flash("Thêm thất bại!", "warning"); throw ex; } }
public ActionResult Create(PostViewModel viewModel) { try { if (ModelState.IsValid) { var model = new Post(); model.Name = viewModel.Name; model.CategoryId = Convert.ToInt32(viewModel.CategoryId); model.Status = viewModel.Status; model.MenuId = viewModel.MenuId; model.Description = viewModel.Description; model.Content = viewModel.Content; model.Deleted = false; model.CreateBy = 1; model.HomeFlag = viewModel.HomeFlag; model.HotFlag = viewModel.HotFlag; model.IsShow = viewModel.IsShow; model.CreateDate = DateTime.Now; model.DepartmentId = 0; model.Alias = XString.ToAscii(model.Name); model.Img = viewModel.Img; model.MoreImgs = viewModel.MoreImgs; _db.Posts.Add(model); _db.SaveChanges(); Notification.set_flash("Lưu thành công!", "success"); ModelState.Clear(); } else { Notification.set_flash("Nhập đầy đủ thông tin!", "warning"); } htmlOption = ""; htmlOption = this.DropdownAdd(0); ViewBag.htmlOption = htmlOption; viewModel = new PostViewModel(); viewModel.ListCategories = Helper.ListCategories().ToList(); return(View(viewModel)); } catch { Notification.set_flash("Thêm thất bại!", "warning"); throw; } }