// GET: Admin/Quans/Edit/5 public ActionResult Edit(int id) { var auth = MySsAuthUsers.GetAuth(); Quan entity = _QuanServ.GetEntry(id); QuanCRUD vm = new QuanCRUD(); vm.Id = entity.Id; vm.MaQuan = entity.MaQuan; vm.TenQuan = entity.TenQuan; if (string.IsNullOrWhiteSpace(vm.ImageThumbnail)) { vm.ImageThumbnail = "/Content/images/sample/shop2.png"; //model.Image; } else { vm.ImageThumbnail = entity.ImageThumbnail; } vm.DiaChi = entity.DiaChi; vm.DienThoai = entity.DienThoai; if (auth.RoleId == 1) { vm.DanhSachNhanVien = new List <User>(); } else { vm.DanhSachNhanVien = __db.Users.Where(w => w.OwnerId == auth.ID); } ViewBag.__auth = auth; vm.DanhSachNhanVienChon = entity.UserQuans.Select(s => s.UserID).ToList(); vm.BanArr = entity.BanArr; vm.ChuQuan = new FrmCreateUserVM(); return(View(vm)); }
// GET: Admin/Quans/Create public ActionResult Create(int catid = -1) { var auth = MySsAuthUsers.GetAuth(); QuanCRUD vm = new QuanCRUD(); vm.DanhSachNhanVien = __db.Users.Where(w => w.OwnerId == auth.ID); vm.ChuQuan = new FrmCreateUserVM(); vm.ChuQuan.ddlGioiTinh = new List <SelectListItem>() { new SelectListItem() { Text = "Nam", Value = "Nam" }, new SelectListItem() { Text = "Nữ", Value = "Nữ" } }; ViewBag.__auth = auth; return(View(vm)); }
public JsonResult Edit(QuanCRUD model) { rs r; using (var trans = new TransactionScope()) { try { var entity = _QuanServ.SingleOrDefault(s => s.Id == model.Id); entity.MaQuan = model.MaQuan; entity.TenQuan = model.TenQuan; if (string.IsNullOrWhiteSpace(model.ImageThumbnail)) { entity.ImageThumbnail = "/Content/images/sample/shop2.png"; //model.Image; } else { entity.ImageThumbnail = model.ImageThumbnail; } entity.DiaChi = model.DiaChi; entity.DienThoai = model.DienThoai; //ban List <int> arr; if (!string.IsNullOrWhiteSpace(model.BanArr)) { try { arr = model.BanArr.Split(',').Select(Int32.Parse).Distinct().ToList(); entity.BanArr = string.Join(",", arr.Select(x => x.ToString()).ToArray()); } catch { throw new Exception("Lỗi, vui lòng kiểm tra giá trị nhập tất cả số bàn ngăn cách nhau bằng dấu phẩy!!!"); } } else { throw new Exception("Vui lòng nhập ít nhất 1 bàn!!!"); } // entity.UserQuans.Clear(); _QuanServ.Save(); //danh sach nhan vien quan ly entity.UserQuans = new List <UserQuan>(); if (model.NhanVienIntIDs != null) { foreach (var item in model.NhanVienIntIDs) { entity.UserQuans.Add(new UserQuan() { QuanID = entity.Id, UserID = item }); } } _QuanServ.Save(); trans.Complete(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult Create(QuanCRUD model) { var __auth = MySsAuthUsers.GetAuth(); rs r; using (TransactionScope tx = new TransactionScope()) { try { //chủ quán SimpleAES __aes = new SimpleAES(); User chuquan = new User(); //pass encode chuquan.Username = model.ChuQuan.Username; chuquan.Password = __aes.EncryptToString(model.ChuQuan.Password); chuquan.RoleId = 2;//chu quan chuquan.UserStatusId = 1; chuquan.Address = model.ChuQuan.Address; chuquan.GioiTinh = model.ChuQuan.GioiTinh; chuquan.Phone = model.ChuQuan.Phone; chuquan.Email = model.ChuQuan.Email; chuquan.Fullname = model.ChuQuan.Username; if (string.IsNullOrWhiteSpace(model.ImageThumbnail)) { chuquan.Image = "/Content/images/sample/shop2.png"; //model.Image; } else { chuquan.Image = model.ImageThumbnail; } __db.Users.Add(chuquan); __db.SaveChanges(); Quan quan = new Quan(); quan.MaQuan = model.MaQuan; quan.TenQuan = model.TenQuan; quan.UserQuans = new List <UserQuan>(); quan.UserId = chuquan.Id; //chuquan quan.DiaChi = model.DiaChi; quan.DienThoai = model.DienThoai; quan.BanArr = "1,2,3,4,5,6,7,8,9,10"; if (string.IsNullOrWhiteSpace(model.ImageThumbnail)) { quan.ImageThumbnail = "/Content/images/sample/account.png"; } else { quan.ImageThumbnail = model.ImageThumbnail; } //danh sach nhan vien quan ly foreach (var item in model.NhanVienIntIDs) { quan.UserQuans.Add(new UserQuan() { QuanID = quan.Id, UserID = item }); } __db.Quan.Add(quan); __db.SaveChanges(); chuquan.QuanDefaultId = quan.Id; __db.SaveChanges(); //product cat & product List <ProductCat> product_cat = new List <ProductCat>(); for (var i = 0; i < 2; i++) { var pc = new ProductCat() { QuanId = quan.Id, Name = "Danh mục mẫu" + (i + 1), Products = new Collection <Product>(), ImageThumbnail = Utils.RandomAnhSample("/Content/images/sample/cat", 1, 2, ".png") }; for (var j = 0; j < 2; j++) { pc.Products.Add(new Product() { ProductName = "Sản phẩm " + (j + 1), MaSo = "MSP-" + j + 1, Price = Utils.RandomGia(), ThumbnailImage = Utils.RandomAnhSample("/Content/images/sample/p", 1, 5, ".png"), }); } product_cat.Add(pc); } __db.ProductCat.AddRange(product_cat); __db.SaveChanges(); r = rs.T("Okay"); tx.Complete(); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } } return(Json(r, JsonRequestBehavior.DenyGet)); }