public static IEnumerable <int?> GetUserTheoMaCauHinhHeThong_GetTheoUserId(string app_code, int?UnitId) { qtUserService _userService = new qtUserService(); qtUser user = new qtUser(); qtUserConfigService _userConfigService = new qtUserConfigService(); IEnumerable <qtUserConfig> danhSachCauhinhUserTheoDonVi = _userConfigService.FindList().Where(x => x.IsActive == true && x.AppCode == app_code); if (UnitId.HasValue) { danhSachCauhinhUserTheoDonVi = danhSachCauhinhUserTheoDonVi.Where(x => x.UnitId == UnitId); } qtUserConfigDetailService _userConfigDetailService = new qtUserConfigDetailService(); List <qtUserConfigDetail> danhSachUserCauHinhTheoDonVi_LanhDao = new List <qtUserConfigDetail>(); foreach (var userConfig in danhSachCauhinhUserTheoDonVi) { IEnumerable <qtUserConfigDetail> danhSachUserMotDonVi = _userConfigDetailService.FindList().Where(x => x.UserConfigId == userConfig.UserConfigId); danhSachUserCauHinhTheoDonVi_LanhDao.AddRange(danhSachUserMotDonVi); } danhSachUserCauHinhTheoDonVi_LanhDao = danhSachUserCauHinhTheoDonVi_LanhDao.OrderBy(x => x.OrderBy).ToList(); return(danhSachUserCauHinhTheoDonVi_LanhDao.Select(x => x.UserId)); }
public ActionResult Index(string urlPrefix, string Username, string Password, bool?Remember) { qtUserService _user = new qtUserService(); if (_user.CheckUserLogin(Username, EncryptUtil.EncryptMD5(Password))) { qtUser user = _user.GetUserLogin(Username, EncryptUtil.EncryptMD5(Password)); if (user != null) { if (Remember != null && Remember == true) { HttpCookie ckUsername = new HttpCookie("username"); ckUsername.Expires = DateTime.Now.AddSeconds(3600); ckUsername.Value = Username; Response.Cookies.Add(ckUsername); HttpCookie ckPassword = new HttpCookie("password"); ckPassword.Expires = DateTime.Now.AddSeconds(3600); ckPassword.Value = EncryptUtil.EncryptMD5(Password); Response.Cookies.Add(ckPassword); } HttpContext.User.Identity.SetUserLogin( new Account(user.UserId, user.UserName, user.UserLogin, user.Password, user.Address, user.Sex.ToString(), user.Email, user.Tel, user.Phone, user.Notes, user.UnitId.ToString(), string.Empty, user.DepartmentId.ToString(), string.Empty, user.PositionId.ToString(), string.Empty) ); string url = String.Empty; if (String.IsNullOrEmpty(urlPrefix)) { url = QuanTriHelper.GetFirstPermissionUrlByUser(user, Config.Application); } else { url = urlPrefix; } // fix url = "/DanhMuc/BaoCao/Index"; if (!string.IsNullOrEmpty(url)) { return(Redirect(url)); } else { ModelState.AddModelError("", "Tài khoản chưa được phân quyền"); } return(View()); } else { ModelState.AddModelError("", "Tài khoản không tồn tại trong hệ thống"); } } else { ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng"); } return(View()); }
public ActionResult Create(int?UserId, string UserName, string UserLogin, string Password, string Email, string Tel, int?SortOrder, int?UnitId, int?DepartmentId, int?PositionId, bool?IsAdmin, bool?Status) { qtUserService _user = new qtUserService(); qtUser user = new qtUser(); if (!UserId.HasValue) { UserId = 0; } user = _user.ThemMoi_HieuChinhThongTinUser( UserId.Value, UserName, UserLogin, Password, SortOrder, null, null, null, Email, Tel, null, IsAdmin, null, UnitId, DepartmentId, PositionId, Status, DateTime.Now); return(RedirectToAction("Index")); }
public static MvcHtmlString OrderHistoryMemberName_UserName(this HtmlHelper helper, int?UserId, string MemberGuid) { string html = string.Empty; if (UserId.HasValue) { qtUserService _user = new qtUserService(); qtUser user = _user.FindByKey(UserId); if (user != null) { html = user.UserName; } } if (!string.IsNullOrEmpty(MemberGuid) || !string.IsNullOrWhiteSpace(MemberGuid)) { shMemberService _member = new shMemberService(); shMember member = _member.FindByKey(MemberGuid); if (member != null) { html = member.MemberName; } } return(new MvcHtmlString(html)); }
public void ThongTin(qtUser user) { qtDepartmentService _department = new qtDepartmentService(); qtUnitService _unit = new qtUnitService(); qtPositionService _position = new qtPositionService(); ViewBag.TenPhong = _department.FindByKey(user.DepartmentId).DepartmentName; ViewBag.TenDonVi = _unit.FindByKey(user.UnitId).UnitName; ViewBag.ChucVu = _position.FindByKey(user.PositionId).PositionName; }
public ActionResult Index(string urlPrefix) { ViewBag.urlPrefix = urlPrefix; qtUser userCookie = CheckCookie(); if (userCookie != null) { qtUserService _user = new qtUserService(); if (_user.CheckUserLogin(userCookie.UserLogin, userCookie.Password)) { qtUser user = _user.GetUserLogin(userCookie.UserLogin, userCookie.Password); if (user != null) { HttpContext.User.Identity.SetUserLogin( new Account(user.UserId, user.UserName, user.UserLogin, user.Password, user.Address, user.Sex.ToString(), user.Email, user.Tel, user.Phone, user.Notes, user.UnitId.ToString(), string.Empty, user.DepartmentId.ToString(), string.Empty, user.PositionId.ToString(), string.Empty) ); string url = String.Empty; if (String.IsNullOrEmpty(urlPrefix)) { url = QuanTriHelper.GetFirstPermissionUrlByUser(user, Config.Application); } else { url = urlPrefix; } // fix url = "/DanhMuc/BaoCao/Index"; if (!string.IsNullOrEmpty(url)) { return(Redirect(url)); } else { ModelState.AddModelError("", "Tài khoản chưa được phân quyền"); } return(View()); } else { ModelState.AddModelError("", "Tài khoản không tồn tại trong hệ thống"); } } else { ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng"); } } return(View()); }
public static string GetFirstPermissionUrlByUser(qtUser user, string appcode) { foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes) { foreach (SiteMapNode childNode in node.ChildNodes) { if (CheckAccessByUser(childNode, appcode, user)) { return(childNode.Url); } } } return(string.Empty); }
public static IEnumerable <qtUser> GetUserTheoMaCauHinhHeThong_GetTheoUser(string app_code, int?UnitId) { qtUserService _userService = new qtUserService(); qtUser user = new qtUser(); qtUserConfigService _userConfigService = new qtUserConfigService(); IEnumerable <qtUserConfig> danhSachCauhinhUserTheoDonVi = _userConfigService.FindList().Where(x => x.IsActive == true && x.AppCode == app_code); if (UnitId.HasValue) { danhSachCauhinhUserTheoDonVi = danhSachCauhinhUserTheoDonVi.Where(x => x.UnitId == UnitId); } qtUserConfigDetailService _userConfigDetailService = new qtUserConfigDetailService(); List <qtUserConfigDetail> danhSachUserCauHinhTheoDonVi_LanhDao = new List <qtUserConfigDetail>(); foreach (var userConfig in danhSachCauhinhUserTheoDonVi) { IEnumerable <qtUserConfigDetail> danhSachUserMotDonVi = _userConfigDetailService.FindList().Where(x => x.UserConfigId == userConfig.UserConfigId); danhSachUserCauHinhTheoDonVi_LanhDao.AddRange(danhSachUserMotDonVi); } danhSachUserCauHinhTheoDonVi_LanhDao = danhSachUserCauHinhTheoDonVi_LanhDao.OrderBy(x => x.OrderBy).ToList(); List <qtUser> danhSanhUser_La_LanhDao = new List <qtUser>(); foreach (var userConfigDetail in danhSachUserCauHinhTheoDonVi_LanhDao) { user = _userService.FindByKey(userConfigDetail.UserId); if (user != null) { if (user.Status.GetValueOrDefault(false)) { yield return(user); } } } }
public static bool CheckAccessByUser(SiteMapNode node, string appcode, qtUser user) { if (user != null) { if (node.Roles.Count == 0) { return(true); } for (int i = 0; i < node.Roles.Count; i++) { if (node.Roles[i] != null) { string role = node.Roles[i].ToString(); qtRoleService _role = new qtRoleService(); return(_role.CheckUserInRole(user.UnitId.Value, user.DepartmentId.Value, user.PositionId.Value, appcode, role)); } } } return(false); }
public static void SaveFileImage(int userid, HttpFileCollectionBase FileDinhKem) { qtUserService _user = new qtUserService(); qtUser user = new qtUser(); if (userid > 0) user = _user.FindByKey(userid); if (FileDinhKem.Count >= 1) { HttpPostedFileBase file = FileDinhKem[0]; if (file.FileName != null && file.FileName != "") { string ramdom = Guid.NewGuid().ToString(); string fordelUpload = HttpContext.Current.Server.MapPath("~/AttachFile/") + ramdom + "_" + file.FileName; file.SaveAs(fordelUpload); user.ImageFile = "~/AttachFile/" + ramdom + "_" + file.FileName; if (userid > 0) _user.Update(user); else _user.Insert(user); } } }
public ActionResult Create(int?id, int?UnitId) { qtUserService _user = new qtUserService(); qtUser user = new qtUser(); if (id.HasValue) { ViewBag.UserId = id; user = _user.FindByKey(id); if (user == null) { ModelState.AddModelError("", "Dữ liệu không tồn tại trong hệ thống. Vui lòng kiểm tra lại"); Departments(null, null); return(View(new qtUser())); } } Departments(user.UnitId, user.DepartmentId); return(View(user)); }
public qtUser CheckCookie() { qtUser user = null; string username = string.Empty, password = string.Empty; if (Request.Cookies["Cusername"] != null) { username = Request.Cookies["Cusername"].Value; } if (Request.Cookies["Cpassword"] != null) { password = Request.Cookies["Cpassword"].Value; } if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { user = new qtUser { UserLogin = username, Password = password } } ; return(user); }
public ActionResult Order(int?p, int?pay_type, string City, string Town, string order_name, string order_address, string order_phone, string order_email, string base_remark) { using (var context = new ShopOnlineDb()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { #region Get Infor login string MemberGuid = string.Empty; bool isCoTaiKhoan = false; if (string.IsNullOrEmpty(User.Identity.GetMemberLogin().MemberGuid) || string.IsNullOrWhiteSpace(User.Identity.GetMemberLogin().MemberGuid)) { //return Redirect("/dang-nhap?urlPrefix=/gio-hang"); isCoTaiKhoan = false; } else { isCoTaiKhoan = true; MemberGuid = User.Identity.GetMemberLogin().MemberGuid; } var cart = Session[CartSession]; if (cart == null) { TempData["Cart"] = "Giỏ hàng trống. Vui lòng thao tác lại."; return(Redirect("/gio-hang")); } cart = cart as List <CartItem>; shSizeService _size = new shSizeService(); decimal price = _size.ListProductPrice_Quantity(cart as List <CartItem>, 0, 0, 0); decimal Feeship = Config.FeeShip; if (price > Config.FeeTotal) { Feeship = 0; } int _Status = OrderStatus.DangXuLy.GetHashCode(); shOrderService _order = new shOrderService(); #endregion #region Tìm nhân viên random được chọn xử lý đơn hàng // ds nhân viên được phân xử lý đơn hàng qtUser UserId = new qtUser(); List <qtUser> dsUser_XuLyDonhang = CommonHelper.GetUserTheoMaCauHinhHeThong_GetTheoUser(Config.TAI_KHOAN_NHAN_DON_HANG, Units.ChiNhanhShowRoom.GetHashCode()).ToList(); int userid_dagiaoviec = 0; IEnumerable <shOrder> dsOrder = _order.DanhSachOrder() .Where(x => x.UserId != null && x.UserId != 0) .OrderByDescending(x => x.OrderId); foreach (var item in dsOrder) { if (item.UserId != null && item.UserId != 0) { userid_dagiaoviec = item.UserId.Value; break; } } for (int i = 0; i < dsUser_XuLyDonhang.Count(); i++) { qtUser user = dsUser_XuLyDonhang[i]; if (user.UserId == userid_dagiaoviec) { if (i == (dsUser_XuLyDonhang.Count() - 1)) { UserId = dsUser_XuLyDonhang[0]; } else if (i < (dsUser_XuLyDonhang.Count() - 1)) { UserId = dsUser_XuLyDonhang[i + 1]; } } } #endregion #region shOrder shOrder order = _order.Insert_Update( null, null, null, MemberGuid, order_name, order_email, order_phone, order_address, price, _Status, null, TypeHelper.ToInt32(Town), TypeHelper.ToInt32(City), Feeship, true, DateTime.Now, pay_type, DateTime.Now, UserId.UserId ); #endregion #region shOrderHistory shOrderHistoryService _orderHistory = new shOrderHistoryService(); shOrderHistory orderHistory = _orderHistory.Insert_Update( null, order.OrderGuid, _Status, User.Identity.GetMemberLogin().MemberGuid, "Đặt hàng", null, true, DateTime.Now); #endregion #region shOrderDetail shOrderDetailService _orderDetail = new shOrderDetailService(); price = 0; decimal total = 0; foreach (var item in cart as List <CartItem> ) { price = _size.ProductPrice(item.SizeGuid); total = price * item.Quantity; _orderDetail.Insert_Update( null, null, null, order.OrderGuid, MemberGuid, item.Product.ProductGuid, item.Product.ProductName, item.SectionGuid, item.SizeGuid, item.Quantity, price, total, true, DateTime.Now, DateTime.Now ); } #endregion #region SEND EMAIL, MESSAGE // 1. Gửi Email tới Quản trị viên xác nhận đơn hàng /// ds User cấu hình nhận Email trong hệ thống IEnumerable <qtUser> dsUser = CommonHelper.GetUserTheoMaCauHinhHeThong_GetTheoUser(Config.TAI_KHOAN_EMAIL_THONG_BAO_TIEP_NHAN_DON_HANG, Units.ChiNhanhShowRoom.GetHashCode()); string noidungdonhang = EmailHelper.NoiDungDonHang(order, cart as List <CartItem>); string noidungEmail = string.Empty; foreach (var user in dsUser) { noidungEmail = string.Empty; qtUnitService _unit = new qtUnitService(); noidungEmail = EmailHelper.NoiDungMailThongBaoQuanTri(_unit.UnitName(Units.ChiNhanhShowRoom.GetHashCode()), 1, noidungdonhang); EmailHelper.ThongBaoEmailDonHangMoi(user.Email, noidungEmail); } if (UserId.UserId > 0) { noidungEmail = string.Empty; qtUnitService _unit = new qtUnitService(); noidungEmail = EmailHelper.NoiDungMailThongBaoQuanTri(_unit.UnitName(Units.ChiNhanhShowRoom.GetHashCode()), 1, noidungdonhang); EmailHelper.ThongBaoEmailDonHangMoi(UserId.Email, noidungEmail); } // 2. Gửi Email xác nhận đơn hàng tới khách hàng noidungEmail = ""; if (isCoTaiKhoan) { noidungEmail = EmailHelper.NoiDungMailThongBaoNguoiDatHang(noidungdonhang); EmailHelper.ThongBaoEmailDonHangMoiToiNguoiDatHang(User.Identity.GetMemberLogin().Email, noidungEmail); } // 3. Gửi thông báo tới Quản trị viên nhận thông báo ThongBaoService _thongbao = new ThongBaoService(); foreach (var user in dsUser) { int?Memberid = null; if (isCoTaiKhoan) { Memberid = User.Identity.GetMemberLogin().MemberId; } _thongbao.InsertOrUpdate( null, "Thông báo đơn hàng mới. Người đặt hàng: " + order_name + ", giá trị: " + Format.FormatDecimalToString(price), "Bạn có đơn hàng mới cần xử lý từ khách hàng: " + order_name + " với đơn hàng tổng giá trị: " + Format.FormatDecimalToString(price) + " lúc: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm") + ". Vui lòng truy cập hệ thống để xử lý", "/DanhMuc/Order/Index/s=" + order.OrderGuid, Memberid, user.UserId, DateTime.Now, false, Config.THONG_BAO_DON_HANG_MOI, null ); } if (UserId.UserId > 0) { int?Memberid = null; if (isCoTaiKhoan) { Memberid = User.Identity.GetMemberLogin().MemberId; } _thongbao.InsertOrUpdate( null, "Thông báo đơn hàng mới. Người đặt hàng: " + order_name + ", giá trị: " + Format.FormatDecimalToString(price), "Bạn có đơn hàng mới cần xử lý từ khách hàng: " + order_name + " với đơn hàng tổng giá trị: " + Format.FormatDecimalToString(price) + " lúc: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm") + ". Vui lòng truy cập hệ thống để xử lý", "/DanhMuc/Order/Index/s=" + order.OrderGuid, Memberid, UserId.UserId, DateTime.Now, false, Config.THONG_BAO_DON_HANG_MOI, null ); } #endregion #region Clear data cookies after order Session[CartSession] = null; #endregion dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); } } } return(Redirect("/thong-tin-ca-nhan")); }