public JsonResult editSLSP(int ctid, int sl) { rs r; using (var __db = new vuong_cms_context()) { using (var tx = new TransactionScope()) { try { var en = __db.CTDonHangs.Find(ctid); en.SoLuong = sl; en.ThanhTien = en.DonGia * en.SoLuong; __db.SaveChanges(); var parent = __db.DonHangs.Find(en.DonHangID); parent.TongTienHang = parent.CTDonHangs.Sum(s => s.DonGia * s.SoLuong); __db.SaveChanges(); tx.Complete(); r = rs.T("Cập nhật thành công!", new { TongTien = parent.TongTienHang.ToMoneyStr(), ThanhTien = en.ThanhTien.ToMoneyStr(), }); } catch (Exception ex) { r = rs.F(ex.Message); } } } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult Upload(int imgtmpid, int thumbw, int thumbh) { var resultList = new List <ViewDataUploadFilesResult>(); var currentContext = HttpContext; filesHelper.UploadAndShowResults(currentContext, resultList, thumbw, thumbh); JsonFiles files = new JsonFiles(resultList); bool isEmpty = !resultList.Any(); if (isEmpty) { return(Json("Error ")); } else { var lst = new List <ImgTmpDetail>(); foreach (var item in files.files) { ImgTmpDetail model = new ImgTmpDetail(); model.FullImage = item.url; model.Thumbnail = item.thumbnailUrl; model.ImgTmpId = imgtmpid; lst.Add(model); } if (lst.Any()) { __db.ImgTmpDetail.AddRange(lst); __db.SaveChanges(); } return(Json(files)); } }
public ActionResult Create(Catalog model, HttpPostedFileBase file) { rs r; if (ModelState.IsValid) { try { if (file.ContentLength > 0) { string _FileName = myNumbers.LayMaNgauNhien10ChuSo() + Path.GetFileName(file.FileName); string _xpath = "/user-uploads/catalog/" + _FileName; string _path = Path.Combine(Server.MapPath("~/user-uploads/catalog"), _FileName); file.SaveAs(_path); model.HinhAnh = _xpath; } else { model.HinhAnh = ""; } __db.Catalog.Add(model); __db.SaveChanges(); r = rs.T("Success!"); } catch (Exception ex) { r = rs.F(ex.Message); } TempData["message"] = r.m; return(RedirectToAction("Index")); } return(View(model)); }
public JsonResult EditProccess(ProductCatCRUD model) { rs r; try { var entity = __db.ProductCat.Find(model.Id); entity.Name = model.Name; //entity.ParentId = (model.ParentId==-1)?null:model.ParentId; entity.Description = model.Description; entity.QuanId = model.QuanId; if (string.IsNullOrWhiteSpace(model.ImageThumbnail)) { entity.ImageThumbnail = "/Content/images/sample/menu1.png"; } else { entity.ImageThumbnail = model.ImageThumbnail; } __db.SaveChanges(); r = rs.T("Ok"); } catch (Exception ex) { r = rs.F(ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public PartialViewResult View(int id) { var entity = __db.Contact.Find(id); ViewBag.Title = entity.HoTen + " > " + entity.Email; entity.ContactStatusId = 2; __db.SaveChanges(); return(PartialView(entity)); }
public JsonResult Create(ProductCRUD model) { rs r; try { Product entity = new Product(); entity.ProductName = model.ProductName; entity.Price = model.Price; entity.Infomation = model.Infomation; entity.ProductCatId = model.ProductCatId; // entity.ProductCatId2 = model.ProductCatId2 == -1 ? null : model.ProductCatId2; entity.IsGiamGia = model.IsGiamGia; entity.Hot = model.Hot; entity.New = model.New; if (string.IsNullOrWhiteSpace(model.ThumbnailImage)) { entity.ThumbnailImage = "/Content/images/sample/product.png"; } else { entity.ThumbnailImage = model.ThumbnailImage; } List <BangGiaCT> gias = new List <BangGiaCT>(); foreach (var item in model.BangGiaCT) { if (item.Price.HasValue && item.Price > 0) { gias.Add(new BangGiaCT() { Ten = item.Ten, Price = item.Price ?? 0, }); } } if (gias.Any()) { entity.BangGiaCT = gias; } entity.SoLuongGia = gias.Count; __db.Product.Add(entity); __db.SaveChanges(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult CapNhatProccess(CapNhatUserVM model) { rs r; SimpleAES __aes = new SimpleAES(); if (ModelState.IsValid) { var __id = MySsAuthUsers.GetAuth().ID; using (var __db = new vuong_cms_context()) { var user = __db.Users.Find(__id); user.Phone = model.Phone; user.Address = model.Address; user.Fullname = model.Fullname; __db.SaveChanges(); r = rs.T("Ok"); } } else { r = rs.F("Vui lòng điền đầy đủ thông tin!"); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult DoiMatKhauProccess(DoiMatKhauVM model) { rs r; SimpleAES __aes = new SimpleAES(); if (ModelState.IsValid) { var __oldpw = __aes.EncryptToString(model.MatKhauHienTai); var __newpw = __aes.EncryptToString(model.MatKhauMoi); var __id = MySsAuthUsers.GetAuth().ID; using (var __db = new vuong_cms_context()) { var user = __db.Users.Find(__id); if (user.Password == __oldpw) { user.Password = __newpw; __db.SaveChanges(); r = rs.T("Ok"); } else { r = rs.F("Mật khẩu hiện tại không chính xác!"); } } } else { r = rs.F("Vui lòng điền đầy đủ thông tin!"); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public rs goitinhtien(GoiTinhTienForm model) { rs r; using (var __db = new vuong_cms_context()) { if (ModelState.IsValid) { var entity = __db.DonHangs.Find(model.DonHangID); if (model.TienKhachDua < entity.TongTienHang) { throw new Exception("Tiền khách đưa không đủ!"); } entity.SoLanGoiTinhTien++; entity.TienKhachDua = model.TienKhachDua; entity.LanCuoiGoiTinhTien = DateTime.Now; __db.SaveChanges(); r = rs.T("Quán đã nhận được yêu cầu gọi tính tiền!", DonHangVM.map(entity)); IHubContext context = GlobalHost.ConnectionManager.GetHubContext <UsersOnLine>(); context.Clients.All.notify_goitinhtien(entity.BaseUserId, "Yêu cầu tính tiền bàn: " + entity.Ban); } else { //all error r = rs.F("Lỗi, vui lòng thử lại. " + string.Join(";", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).Distinct())); } } return(r); }
public rs dat_hang(DatHangForm model) { rs r; using (var __db = new vuong_cms_context()) { if (ModelState.IsValid) { using (var tx = __db.Database.BeginTransaction()) { try { //donhang DonHang donhang = new DonHang(); donhang.UserId = model.UserId; donhang.GhiChuDonHang = model.GhiChu; donhang.TrangThaiGiaoHangId = 1; donhang.TrangThaiThanhToanId = 1; //ctdh donhang.CTDonHangs = new Collection <CTDonHang>(); foreach (var gio in model.ChiTietDonHang) { var sanphamdb = __db.Product.Find(gio.SanPhamId); CTDonHang newct = new CTDonHang() { SanPhamId = gio.SanPhamId, SoLuong = gio.SoLuong, }; newct.ThanhTien = newct.DonGia * newct.SoLuong; donhang.CTDonHangs.Add(newct); } var __tongtiendonhang = donhang.CTDonHangs.Sum(s => s.DonGia * s.SoLuong); donhang.TongTienHang = __tongtiendonhang; //user __db.DonHangs.Add(donhang); __db.SaveChanges(); //com tx.Commit(); r = rs.T("Đặt hàng thành công"); } catch (Exception ex) { r = rs.F("Lỗi máy chủ " + ex.Message); tx.Rollback(); } } } else { //all error r = rs.F(string.Join(";", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage).Distinct())); } } return(r); }
public JsonResult updateGiaShipTinhThanh(int Id, int GiaShip) { rs r; try { var up = __db.Province.Find(Id); up.GiaShip = GiaShip; __db.Database.ExecuteSqlCommand("UPDATE District SET GiaShip=" + GiaShip + " WHERE ProvinceId=" + Id); __db.SaveChanges(); r = rs.T("Ok"); } catch (Exception ex) { r = rs.F(ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult ajax_dathang(TaoDonHangVM model) { var __auth = MySsAuthUsers.GetAuth(); rs r = rs.T("Ok"); try { var __user = __db.Users.Find(__auth.ID); DonHang dh = new DonHang(); dh.GhiChuDonHang = model.GhiChu; //dh.BanId = model.BanId != -1 ? model.BanId : null; dh.QuanId = model.QuanId; dh.TrangThaiGiaoHangId = model.TrangThaiGiaoHangId; dh.TrangThaiThanhToanId = model.TrangThaiThanhToanId; dh.UserId = __auth.ID; dh.BaseUserId = __user.OwnerId != null?__user.OwnerId.Value:__auth.ID; dh.CTDonHangs = new Collection <CTDonHang>(); dh.TongTienHang = model.GioHang.Sum(s => s.Price * s.SoLuong); dh.Ban = model.Ban; foreach (var item in model.GioHang) { dh.CTDonHangs.Add(new CTDonHang() { SanPhamId = item.ProductId, DonGia = item.Price, ThanhTien = item.ThanhTien, SoLuong = item.SoLuong, }); } //save __db.DonHangs.Add(dh); __db.SaveChanges(); } catch (Exception ex) { r = rs.F(ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult Create(ProductCRUD model) { rs r; try { var findThumbs = __db.ImgTmp.Find(model.ImgTmpId); Product entity = new Product(); entity.MaSP = model.MaSP; entity.ProductName = model.ProductName; entity.ThumbnailImage = model.ThumbnailImage; entity.Price = model.Price; entity.Infomation = model.Infomation; entity.ProductCatId = model.ProductCatId; entity.MainProduct = model.MainProduct; entity.ImgTmpId = model.ImgTmpId; entity.ConHang = model.ConHang; entity.IsBanChay = model.IsBanChay; //first thumbs if (findThumbs.ImgTmpDetails.Any()) { var firstOrDefault = findThumbs.ImgTmpDetails.FirstOrDefault(f => f.IsMain); if (firstOrDefault == null) { firstOrDefault = findThumbs.ImgTmpDetails.FirstOrDefault(); if (firstOrDefault != null) { entity.ThumbnailImage = firstOrDefault.Thumbnail; } else { entity.ThumbnailImage = "http://file.qdnd.vn/image/images/noimages.png"; } } else { entity.ThumbnailImage = firstOrDefault.Thumbnail; } } __db.Product.Add(entity); __db.SaveChanges(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult EditProccess(ProductCatCRUD model) { rs r; try { var entity = __db.ProductCat.Find(model.Id); entity.Name = model.Name; entity.ShowInProduct = model.ShowInProduct; entity.ParentId = (model.ParentId == -1)?null:model.ParentId; entity.Description = model.Description; __db.SaveChanges(); r = rs.T("Ok"); } catch (Exception ex) { r = rs.F(ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult ajax_create_thuc_don(ThucDonVM thucdon) { rs r; try { ThucDon td = new ThucDon(); td.TenThucDon = thucdon.TenThucDon; td.QuanId = thucdon.QuanId; td.Icon = thucdon.Icon; __db.ThucDon.Add(td); __db.SaveChanges(); thucdon.Id = td.Id; r = rs.T("Ok", thucdon); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public ActionResult Detail(int id, string seo_title = "") { var baiviet = __db.Article.Find(id); baiviet.LuotXem += 1; __db.SaveChanges(); TinTucChiTietView model = new TinTucChiTietView(); model.BaiViet = baiviet; model.LienQuan = __db.Article.Where(w => w.CategoryId == model.BaiViet.CategoryId).OrderByDescending(q => q.CreatedDate).Take(8).ToList(); return(View(model)); }
public JsonResult Create(ArticleCRUD model) { rs r; try { Article entity = new Article(); entity.CategoryId = model.CategoryId; entity.Title = model.Title; entity.Content = model.Content; entity.ImageThumbnail = model.ImageThumbnail; entity.SEOTitle = model.SEOTitle; entity.Description = model.Description; entity.FontAwesomeIcon = model.FontAwesomeIcon; __db.Article.Add(entity); __db.SaveChanges(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult Create(FrmCreateUserVM model) { var __auth = MySsAuthUsers.GetAuth(); rs r; if (_userServ.Count(s => s.Username == model.Username) == 0) { try { SimpleAES __aes = new SimpleAES(); User entity = new User(); //pass encode entity.Username = model.Username; entity.Password = __aes.EncryptToString(model.Password); entity.RoleId = model.RoleId; entity.UserStatusId = 1; entity.Address = model.Address; entity.Phone = model.Phone; entity.GioiTinh = model.GioiTinh; entity.Fullname = model.Username; entity.OwnerId = __auth.ID; entity.Image = model.Image; entity.UserQuans = new Collection <UserQuan>(); //danh sach nhan vien quan ly foreach (var item in model.QuanIntIDs) { entity.UserQuans.Add(new UserQuan() { QuanID = item, UserID = entity.Id }); } __db.Users.Add(entity); __db.SaveChanges(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } } else { r = rs.F("Lỗi:tên đăng nhập đã tồn tại vui lòng chọn tên khác"); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public ActionResult Edit(ThongTin vm) { var model = __db.ThongTin.Find(vm.Id); if (model != null) { model.TieuDe = vm.TieuDe; model.NoiDung = vm.NoiDung; __db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "Không tìm thấy dữ liệu!"); } return(View("Index", model)); }
public JsonResult Create(BanCRUD model) { rs r; try { Ban entity = new Ban(); entity.MaBan = model.MaBan; entity.TenBan = model.TenBan; entity.QuanId = model.QuanId; __db.Ban.Add(entity); __db.SaveChanges(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult toggleHetHang(int id) { rs r; try { using (var __db = new vuong_cms_context()) { var en = __db.CTDonHangs.Find(id); __db.SaveChanges(); r = rs.T("Cập nhật thành công!"); } } catch (Exception ex) { r = rs.F(ex.Message); throw; } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult Create(FrmCreateUserVM model) { rs r; if (_userServ.Count(s => s.Username == model.Username) == 0) { try { SimpleAES __aes = new SimpleAES(); User entity = new User(); //pass encode entity.Username = model.Username; entity.Password = __aes.EncryptToString(model.Password); entity.RoleId = model.RoleID; entity.UserStatusId = 1; entity.IsVip1 = model.IsVip; if (model.IsVip) { entity.NgayVip = DateTime.Now; entity.ChuThichVip = "Nâng cấp thủ công"; } else { entity.ChuThichVip = "Tự động"; } __db.Users.Add(entity); __db.SaveChanges(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } } else { r = rs.F("Lỗi:tên đăng nhập đã tồn tại vui lòng chọn tên khác"); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult Create(ThongBao model) { rs r; try { ThongBao entity = new ThongBao(); //pass encode entity.TieuDe = model.TieuDe; entity.NoiDung = model.NoiDung; entity.IsHienThi = model.IsHienThi; __db.ThongBao.Add(entity); __db.SaveChanges(); r = rs.T("Okay"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public JsonResult ajax_reply(ReplyPhanHoiForm model) { rs r; if (ModelState.IsValid) { try { var donhang = __db.DonHangs.Find(model.DonHangId); var quan = donhang.Quan; var __auth = MySsAuthUsers.GetAuth(); var newRep = new GopYReply() { GopYId = model.GopYId, NoiDung = model.NoiDungPhanHoi, UserReplyId = __auth.ID, }; __db.GopYReply.Add(newRep); __db.SaveChanges(); OneSignalAPI.SendMsgToUser(quan.TenQuan + " #TH" + donhang.Id, model.NoiDungPhanHoi, donhang.UniqueID); r = rs.T("Đã phản hồi thành công!"); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } } else { r = rs.F("Lỗi, vui lòng thử lại. " + string.Join(";", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage).Distinct())); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public ActionResult EditProfile(EditUserVM vm) { if (ModelState.IsValid) { try { var user = __db.Users.Find(vm.ID); user.Email = vm.Email; user.Phone = vm.DienThoai; user.Fullname = vm.HoTen; user.Address = vm.DiaChi; __db.SaveChanges(); TempData["message"] = "Cập nhật thành công"; return(RedirectToAction("Profile")); } catch (Exception ex) { TempData["message"] = "Error: " + ex.Message; } } return(View(vm)); }
public rs gopy(GopYDonHangForm model) { rs r; using (var __db = new vuong_cms_context()) { if (ModelState.IsValid) { var entity = __db.DonHangs.Find(model.DonHangID); GopY gop = new GopY(); gop.DonHangId = model.DonHangID; gop.NoiDungGopY = model.NoiDung; gop.CreatedDate = DateTime.Now; __db.GopY.Add(gop); __db.SaveChanges(); r = rs.T("Chúng tôi đã ghi nhận góp ý của bạn, xin cám ơn!", DonHangVM.map(entity)); IHubContext context = GlobalHost.ConnectionManager.GetHubContext <UsersOnLine>(); if (entity.HinhThucMuaHangId == 1) { context.Clients.All.notify_gopy(entity.BaseUserId, "Nhận được góp ý tại bàn: " + entity.Ban); } else { context.Clients.All.notify_gopy(entity.BaseUserId, "Nhận được góp ý *" + entity.HinhThucMuaHang.Ten + "*"); } } else { //all error r = rs.F("Lỗi, vui lòng thử lại. " + string.Join(";", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage).Distinct())); } } return(r); }
public JsonResult AjaxDatQuanChinh(int quanid) { rs r; try { var __auth = MySsAuthUsers.GetAuth(); var user = __db.Users.Find(__auth.ID); user.QuanDefaultId = quanid; __db.SaveChanges(); r = rs.T("Ok"); } catch (Exception ex) { r = rs.F(ex.Message); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public ActionResult Index(ThanhToanVM model) { var giohang = GioHang.Lay(); if (!giohang.CTGioHangs.Any()) { ModelState.AddModelError(string.Empty, "Giỏ hàng rỗng"); } var uuu = MySsAuthUsers.GetAuth(); if (uuu == null) { ModelState.AddModelError(string.Empty, "Vui lòng đăng nhập"); } bool status = false; using (var __db = new vuong_cms_context()) { if (ModelState.IsValid) { using (var tx = __db.Database.BeginTransaction()) { try { //donhang DonHang donhang = new DonHang(); donhang.TongTienHang = giohang.TongTienHang; donhang.TrangThaiGiaoHangId = 1; donhang.TrangThaiThanhToanId = 1; //ctdh donhang.CTDonHangs = new Collection <CTDonHang>(); foreach (var gio in giohang.CTGioHangs) { donhang.CTDonHangs.Add(new CTDonHang() { SanPhamId = gio.SanPhamId, SoLuong = gio.SoLuong, ThanhTien = gio.ThanhTien, DonGia = gio.DonGia, }); } //user if (uuu != null) { donhang.UserId = uuu.ID; } __db.DonHangs.Add(donhang); __db.SaveChanges(); //com tx.Commit(); } catch (Exception ex) { tx.Rollback(); } } } } return(View(model)); }
public rs dat_hang_qr(DatHangQRForm model) { rs r; using (var __db = new vuong_cms_context()) { if (ModelState.IsValid) { using (var tx = __db.Database.BeginTransaction()) { try { var quan = __db.Quan.FirstOrDefault(f => f.Id == model.QuanId); //var ban = __db.Ban.First(f => f.Id == model.BanId && f.QuanId == model.QuanId); if (quan == null) { throw new Exception("Bàn và quán không hợp lệ, vui lòng thử lại!"); } var BanArr = new List <int>(); if (!string.IsNullOrWhiteSpace(quan.BanArr)) { try { BanArr = quan.BanArr.Split(',').Select(Int32.Parse).Distinct().ToList(); } catch { } } if (model.HinhThucMuaHangId == 1 && !BanArr.Contains(model.Ban)) { throw new Exception("Số Bàn nhập không tồn tại trong quán " + quan.TenQuan + ", vui lòng thử lại!"); } //donhang DonHang donhang = new DonHang(); //donhang.BanId = model.BanId; donhang.Ban = model.Ban; donhang.QuanId = model.QuanId; donhang.GhiChuDonHang = ""; donhang.TrangThaiGiaoHangId = 1; donhang.TrangThaiThanhToanId = 1; donhang.UserId = null; donhang.BaseUserId = quan.UserId; donhang.DeviceType = 2;//mobile donhang.UniqueID = model.UniqueID; donhang.ModelNumber = model.ModelNumber; donhang.HinhThucMuaHangId = model.HinhThucMuaHangId; donhang.SDT = model.SDT; donhang.YeuCauKhac = model.YeuCauKhac; donhang.DiaChiGiaoHang = model.DiaChiGiaoHang; donhang.TienKhachDua = 0; //ctdh donhang.CTDonHangs = new Collection <CTDonHang>(); foreach (var gio in model.ChiTietDonHang) { Product sp = __db.Product.FirstOrDefault(f => f.Id == gio.SanPhamId && f.ProductCat.QuanId == model.QuanId); if (sp == null) { throw new Exception("Sản phẩm không tồn tại, vui lòng xóa tất cả sản phẩm giỏ hàng và chọn lại!"); } var price = sp.Price; string tengia = ""; if (gio.GiaId != 0) { var check_gia = __db.BangGiaCT.FirstOrDefault(f => f.Id == gio.GiaId); if (check_gia == null) { throw new Exception("Bảng giá sản phẩm đã cũ, vui lòng tạo lại đơn hàng!"); } else { price = check_gia.Price; tengia = check_gia.Ten; } } CTDonHang newct = new CTDonHang() { SanPhamId = gio.SanPhamId, SoLuong = gio.SoLuong, DonGia = price, ThucDonId = gio.ThucDonId, TenGia = tengia, GiaId = gio.GiaId, }; newct.ThanhTien = newct.DonGia * newct.SoLuong; donhang.CTDonHangs.Add(newct); } var __tongtiendonhang = donhang.CTDonHangs.Sum(s => (int?)s.DonGia * s.SoLuong) ?? 0; donhang.TongTienHang = __tongtiendonhang; //user __db.DonHangs.Add(donhang); __db.SaveChanges(); //com tx.Commit(); r = rs.T("Đặt hàng thành công"); IHubContext context = GlobalHost.ConnectionManager.GetHubContext <UsersOnLine>(); context.Clients.All.notify_new_donhang(donhang.BaseUserId, "Đơn hàng mới tại bàn: " + donhang.Ban); } catch (Exception ex) { r = rs.F(ex.Message); tx.Rollback(); } } } else { //all error r = rs.F("Lỗi, vui lòng thử lại. " + string.Join(";", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage).Distinct())); } } return(r); }
public JsonResult Create(FrmCreateUserVM model) { rs r; if (_userServ.Count(s => s.Username == model.Username) == 0) { using (TransactionScope tx = new TransactionScope()) { try { SimpleAES __aes = new SimpleAES(); User entity = new User(); //pass encode entity.Username = model.Username; entity.Password = __aes.EncryptToString(model.Password); entity.RoleId = model.RoleId; entity.UserStatusId = 1; entity.Address = model.Address; entity.GioiTinh = model.GioiTinh; entity.Phone = model.Phone; entity.Email = model.Email; entity.Fullname = model.Username; entity.Image = model.Image; __db.Users.Add(entity); __db.SaveChanges(); //quan /*Quan quan = new Quan() * { * UserId = entity.Id, * TenQuan = "Quán mẫu", * MaQuan = "QUAN_MAU", * DiaChi = "Tp. HCM", * DienThoai = "0123456789", * BanArr = "1,2,3,4,5,6,7,8,9,10", * ImageThumbnail = Utils.RandomAnhSample("/Content/images/sample/shop",1,2,".png") * }; * __db.Quan.Add(quan); * __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(); * * //thuc don * var dssp = __db.Product.Where(w => w.ProductCat.QuanId == quan.Id).Select(s=>s.Id).ToList(); * List<ThucDon> tds = new List<ThucDon>(); * for (var i = 0; i < 2; i++) * { * ThucDon td = new ThucDon(); * td.QuanId = quan.Id; * td.Icon = Utils.RandomAnhSample("/Content/images/sample/menu", 1, 3, ".png"); * td.TenThucDon = "Thực đơn mẫu" + (i + 1); * td.ThucDonCTs = new Collection<ThucDonCT>(); * * td.ThucDonCTs.Add(new ThucDonCT() * { * ProductId = dssp[i], * }); * * tds.Add(td); * } * __db.ThucDon.AddRange(tds); * __db.SaveChanges(); */ r = rs.T("Okay"); tx.Complete(); } catch (Exception ex) { r = rs.F("Lỗi: " + ex.Message); } } } else { r = rs.F("Lỗi:tên đăng nhập đã tồn tại vui lòng chọn tên khác"); } return(Json(r, JsonRequestBehavior.DenyGet)); }