public ActionResult Delete(int id) { try { SysRole role = CurrentUser.Role(3).Role(); bool canDelete = role.SysRolePermission.Where(x => x.MenuId == 3910 && x.PermissionId == 3 && x.PermissionFlag).Count() > 0; if (!canDelete) { return(RedirectToAction("Index", "Account", new { msg = "ไม่มีสิทธิ์ในการลบข้อมูล", msgType = AlertMsgType.Danger })); } SysAccount ob = db.SysAccount.Find(id); if (ob == null) { return(RedirectToAction("Index", "Account", new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning })); } var accountRoles = db.SysAccountRole.Where(x => x.AccountId == id); db.SysAccountRole.RemoveRange(accountRoles); db.SysAccount.Remove(ob); db.SaveChanges(); return(RedirectToAction("Index", "Account", new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { return(RedirectToAction("Index", "Account", new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContext ctx = HttpContext.Current; if (ctx.Request.Cookies["sid"] != null) { HttpCookie ckSid = ctx.Request.Cookies["sid"]; ckSid.Expires = DateTime.Now.AddMonths(1); if (ctx.Session["sid"] == null) { ctx.Session["sid"] = ckSid.Value; } ctx.Response.SetCookie(ckSid); } // check if session is supported if (HttpContext.Current.Session["sid"] == null) { filterContext.Result = new RedirectResult("~/Authen"); return; } else { string constr = ConfigurationManager.AppSettings[ConfigKey.CONNECTION_DB]; int sid = HttpContext.Current.Session["sid"].ToString().ParseInt(); UnitOfWork uow = new UnitOfWork(constr); SysAccount ob = uow.Modules.Account.Get(sid); if (ob == null) { filterContext.Result = new RedirectResult("~/Authen"); return; } } base.OnActionExecuting(filterContext); }
private ActionResult ViewProfile(SysAccount ob, string msg, AlertMsgType?msgType) { try { if (Session["sid"] == null || ob == null) { throw new Exception("กรุณาเข้าสู่ระบบใหม่อีกครั้ง"); } if (!string.IsNullOrWhiteSpace(msg)) { WidgetAlertModel alert = new WidgetAlertModel() { Message = msg }; if (msgType.HasValue) { alert.Type = msgType.Value; } ViewBag.Alert = alert; } return(View("Profile", ob)); } catch (Exception ex) { return(RedirectToAction("Index", new { controller = "Home", msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
public JsonResult Edit(SysAccount model) { try { if (model.SysAccountId > 0) { var entity = _SysAccountService.GetById(model.SysAccountId); //修改 entity.EditTime = DateTime.Now; entity.NickName = model.NickName; entity.MobilePhone = model.MobilePhone; entity.BaseImageId = model.BaseImageId; entity.Remarks = model.Remarks; _SysAccountService.Update(entity); } else { //添加 model.PassWord = MD5Util.GetMD5_32(model.PassWord); model.EditTime = DateTime.Now; model.CreateTime = DateTime.Now; model.IsDelete = (int)IsDeleteEnum.效; model.Status = (int)EnabledEnum.效; _SysAccountService.Insert(model); } return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet)); } }
public ActionResult MenuSystem(int siteId, string name = "_lyMenu") { UnitOfWork uw = new UnitOfWork(); List <SysMenu> md = new List <SysMenu>(); if (Session["sid"] != null) { long uid = long.TryParse(Session["sid"]?.ToString(), out uid) ? uid : 0; SysAccount usr = uw.Account.Get(uid); SysAccountRole role = usr.Role(siteId); int roleId = role.RoleId; var data = (from d in db.SysMenu join r in db.SysRolePermission on d.MenuId equals r.MenuId where d.MenuLevel == 1 && d.SiteId == siteId && d.FlagActive && r.RoleId == roleId && r.PermissionId == 1 && r.PermissionFlag orderby d.MenuOrder ascending select d); md = data.ToList(); ViewData["RoleId"] = roleId; } //if (ViewData["MenuCurrent"] != null) { md.Current = (int)ViewData["MenuCurrent"]; } //md.Data = data.ToList(); return(PartialView(name, md)); }
public ActionResult SetStaff() { int accountId = Request.Form["account_id"].ParseInt(); SysAccount acc = uow.Account.Get(accountId); int staffId = Request.Form["staff_id"].ParseInt(); CalcAccountStaff ob = new CalcAccountStaff() { AccountId = accountId, StaffId = staffId }; if (db.CalcAccountStaff.Where(x => x.AccountId == ob.AccountId && x.StaffId == ob.StaffId).Count() > 0) { string msg = "ข้อมูลดังกล่าวมีอยู่แล้วในระบบ"; return(ViewDetail(acc, msg, AlertMsgType.Danger)); } db.CalcAccountStaff.Add(ob); db.SaveChanges(); return(RedirectToAction("Detail", new { id = accountId, controller = "Account", msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); }
public void Delete(SysAccount ob) { if (IsExist(ob.AccountId)) { db.SysAccount.Remove(ob); } }
public ActionResult ProfileMe(string msg, AlertMsgType?msgType) { int id = Session["sid"].Convert2String().ParseInt(); SysAccount ob = uow.Modules.Account.Get(id); return(ViewProfile(ob, msg, msgType)); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContext ctx = HttpContext.Current; if (ctx.Request.Cookies["sid"] != null) { HttpCookie ckSid = ctx.Request.Cookies["sid"]; ckSid.Expires = DateTime.Now.AddMonths(1); if (ctx.Session["sid"] == null) { ctx.Session["sid"] = ckSid.Value; } ctx.Response.SetCookie(ckSid); } // check if session is supported if (ctx.Session["sid"] == null) { filterContext.Result = new RedirectResult("~/Authen"); return; } else { int sid = ctx.Session["sid"].ToString().ParseInt(); UnitOfWork uow = new UnitOfWork(); SysAccount ob = uow.db.SysAccount.Find(sid); if (ob == null) { filterContext.Result = new RedirectResult("~/Authen"); return; } } base.OnActionExecuting(filterContext); }
public async Task <ActionResult> Index(SysAccount item) { var currentUser = AuthenticationExtends.CurrentUser; if (currentUser == null) { ViewBag.Message = "Kiểm tra lại thông tin đăng nhập ! ,\n Có thể có ai đó đã dùng tài khoản của bạn"; } else { bool checkChange = false; if (currentUser.ID == item.ID) { if (!string.IsNullOrEmpty(item.Name)) { if (currentUser.Name != item.Name) { currentUser.Name = item.Name; checkChange = true; } } if (!string.IsNullOrEmpty(item.Avatar)) { if (item.Avatar != currentUser.Avatar) { currentUser.Avatar = item.Avatar; checkChange = true; } } if (item.BirthDay > DateTime.MinValue) { if (item.BirthDay != currentUser.BirthDay) { currentUser.BirthDay = item.BirthDay; checkChange = true; } } if (!string.IsNullOrEmpty(item.Pass)) { if (Security.Encrypt(item.Pass) != currentUser.Pass) { currentUser.Pass = Security.Encrypt(item.Pass); checkChange = true; } } if (checkChange) { await _sysAccounts.InsertItemAsync(currentUser); } } else { ViewBag.Message = "Đây không phải tài khoản của bạn"; } } return(View()); }
public ActionResult Detail(int?id, string msg, AlertMsgType?msgType) { SysAccount ob = uow.Modules.Account.Get(id ?? 0); if (ob.AccountId <= 0) { ob.FlagStatus = 1; } return(ViewDetail(ob, msg, msgType)); }
public void Set(SysAccount ob) { if (ob.AccountId <= 0) { db.SysAccount.Add(ob); } else { db.Entry(ob).State = EntityState.Modified; } }
/// <summary> /// 初始化数据 /// </summary> public void InitUserInfo() { SysAccount account = userService.Get(userId); if (null != account) { this.txtCode.Text = account.Code; this.txtName.Text = account.Name; this.drpUserType.SelectedValue = account.IsEnabled == true ? "1" : "0"; } }
/// <summary> /// 页面初始化 /// </summary> private void InitCtrls() { using (WXDBEntities db = new WXDBEntities()) { int id = UserId; SysAccount xSysAccount = db.SysAccount.Where(a => a.AccountID == id).FirstOrDefault(); txtLoginName.Text = xSysAccount.LoginName; txtMail.Text = xSysAccount.Email; txtMobile.Text = xSysAccount.Mobile; txtPhone.Text = xSysAccount.Phone; txtRealName.Text = xSysAccount.RealName; } }
public ActionResult SignIn() { string username = Request.Form["username"].ValidString(); string password = Request.Form["password"].ValidString(false); bool flagRemember = Request.Form["remember"].ParseBoolean(false); SysAccount ob = uow.Modules.Account.GetByUsernameOrEmail(username); Dictionary <string, dynamic> routeObject = new Dictionary <string, dynamic>(); if (ob == null) { logger.LogInfo("[Authen] Cannot found user " + username); Session.Remove("sid"); routeObject.Add("msg", "ข้อมูลเข้าสู่ระบบไม่ถูกต้อง"); return(UrlRedirect(PathHelper.Authen, routeObject)); } else { if (!Crypto.VerifyHashedPassword(ob.AccountPassword, password)) { logger.LogInfo("[Authen] Password not matched for " + username); Session.Remove("sid"); routeObject.Add("msg", "ข้อมูลเข้าสู่ระบบไม่ถูกต้อง"); return(UrlRedirect(PathHelper.Authen, routeObject)); } else { Session["sid"] = ob.AccountId; if (flagRemember) { HttpCookie ckSid; if (Request.Cookies["sid"] == null) { ckSid = new HttpCookie("sid", ob.AccountId.ToString()) { Expires = DateTime.Now.AddHours(1) }; } else { ckSid = Request.Cookies["sid"]; ckSid.Value = ob.AccountId.ToString(); ckSid.Expires = DateTime.Now.AddHours(1); } Response.SetCookie(ckSid); } return(UrlRedirect(PathHelper.Home)); } } }
public async Task <IActionResult> SignIn(string Name, string Pass, string Email) { string _sPass = Security.Encrypt(Pass); if (string.IsNullOrEmpty(Name)) { var user = _sysAccounts.GetLogin(Email.ToLower(), _sPass); if (user != null) { user.Role = _sysRoles.GetItemByID(user.RoleID); await _httpContext.HttpContext.SetLoginAsync(user); var url = HttpContext.Request.Query["ReturnUrl"]; if (string.IsNullOrEmpty(url)) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(url)); } } ViewBag.Message = "Password hoặc mật khẩu không đúng"; } else { if (_sysAccounts.GetItemByEmail(Email) == null) { SysAccount account = new SysAccount() { Name = Name, Pass = Pass, Email = Email, Activity = true, RoleID = 2, Created = DateTime.Now }; await _sysAccounts.InsertItemAsync(account); ViewBag.Message = "Đăng ký thành công"; } else { ViewBag.Message = "Email đã tồn tại"; } } return(View()); }
public async Task <bool> StartWeb() { SysAccount account = new SysAccount() { Name = "Hoàng Thái Long", Avatar = "NoImage", Email = "*****@*****.**", RoleID = 1, Pass = Security.Encrypt("123"), UserCreated = 1, Activity = true, }; await _sysAccount.InsertItemAsync(account); return(true); }
/// <summary> /// 保存 /// </summary> /// <param name="model">model</param> /// <returns></returns> public ResultEx Save(SysAccount model) { using (var dbScope = _dbScopeFactory.Create()) { var db = dbScope.DbContexts.Get <WebDbContext>(); if (model.Id == 0) { db.SysAccounts.Add(model); } else { db.Entry(model).State = System.Data.Entity.EntityState.Modified; } return(ResultEx.Init(db.SaveChanges() > 0)); } }
protected void btnSave_Click(object sender, EventArgs e) { try { ISysAccountService userService = IoC.Resolve <ISysAccountService>(); if (this.txtCode.Text.Trim().Length < 6 || this.txtCode.Text.Trim().Length > 16) { JsAlert("登录名验证错误!"); return; } if (this.txtPassWord.Text.Trim().Length < 6 || this.txtPassWord.Text.Trim().Length > 16) { JsAlert("登录密码验证错误!"); return; } if (!userService.IsUnique(this.txtCode.Text.Trim())) { JsAlert("登录名已经存在!"); return; } SysAccount account = new SysAccount(); account.Code = this.txtCode.Text.Trim(); account.Name = this.txtName.Text.Trim(); account.PassWord = this.txtPassWord.Text.Trim(); account.IsEnabled = true; if (userService.AddAccount(account)) { this.txtCode.Text = string.Empty; this.txtName.Text = string.Empty; this.txtPassWord.Text = string.Empty; JsAlert("保存成功!", true); } else { JsAlert("保存失败,请稍后再试!"); } } catch (Exception ex) { JsAlert("保存失败,请稍后再试!"); } }
public ActionResult Delete() { try { long id = Request.Form["AccountId"].ParseLong(); SysAccount ob = uow.Modules.Account.Get(id); if (ob == null) { return(RedirectToAction("Index", "Account", new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning })); } uow.Modules.Account.DeleteBySQL(ob); // uow.SaveChanges(); return(RedirectToAction("Index", "Account", new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { return(RedirectToAction("Index", "Account", new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
private ActionResult ViewDetail(SysAccount ob, string msg, AlertMsgType?msgType) { try { if (ob == null) { throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง"); } if (!string.IsNullOrWhiteSpace(msg)) { WidgetAlertModel alert = new WidgetAlertModel() { Message = msg }; if (msgType.HasValue) { alert.Type = msgType.Value; } ViewBag.Alert = alert; } ViewData["optRole"] = uow.Role.Gets(1, 0, 3); ViewData["optRoleCal"] = uow.Role.Gets(1, 0, 3); ViewData["optStaff"] = (from d in db.SysAccount where d.AccountId != ob.AccountId && !db.CalcAccountStaff.Where(x => x.AccountId == ob.AccountId).Select(x => x.AccountId).Contains(d.AccountId) select d).ToList(); return(View("Detail", ob)); } catch (Exception ex) { return(RedirectToAction("Index", new { area = "", controller = "Account", msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
public JsonResult CreateBusinessAccount(int id) { try { var businessModel = _businessInfoService.GetById(id); if (businessModel != null && businessModel.BusinessInfoId > 0) { //创建商家帐号实体模型 var model = new SysAccount(); var _date = DateTime.Now; model.Account = "yssgadmin" + businessModel.BusinessInfoId; model.NickName = businessModel.Name; model.PassWord = MD5Util.GetMD5_32("123456"); model.MobilePhone = businessModel.Mobile; model.SysRoleId = (int)RoleTypeEnum.商家; model.BusinessInfoId = businessModel.BusinessInfoId; model.BaseImageId = businessModel.BaseImageId; model.Status = (int)EnabledEnum.效; model.IsDelete = (int)IsDeleteEnum.效; model.CreateTime = _date; model.EditTime = _date; model.LoginTime = _date; //添加 _sysAccountService.Insert(model); } else { return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet)); }
public static bool IsValid(this SysAccount ob, out string errorMsg) { errorMsg = string.Empty; if (ob == null) { errorMsg = "ไม่พบข้อมูล"; return(false); } else { List <string> err = new List <string>(); if (string.IsNullOrWhiteSpace(ob.AccountUsername)) { err.Add("กรุณาระบุชื่อบัญชี"); } if (string.IsNullOrWhiteSpace(ob.AccountFirstName)) { err.Add("กรุณาระบุชื่อผู้ใช้งาน"); } if (string.IsNullOrWhiteSpace(ob.AccountPassword)) { err.Add("กรุณาระบุรหัสผ่าน"); } if (string.IsNullOrWhiteSpace(ob.AccountEmail)) { err.Add("กรุณาระบุอีเมล์"); } if (err.Count > 0) { errorMsg = "กรุณาตรวจสอบข้อมูลต่อไปนี้"; foreach (string s in err) { errorMsg += @"{\n}- " + s; } return(false); } return(true); } }
/// <summary> /// 创建管理员帐号 /// </summary> #region private void CreateAccount() private void CreateAccount() { using (WXDBEntities db = new WXDBEntities()) { SysAccount xSysAccount = new SysAccount(); xSysAccount.LoginName = txtLoginName.Text; xSysAccount.Password = Encrypt.MD5(txtPass.Text); xSysAccount.Email = txtMail.Text; xSysAccount.Mobile = txtMobile.Text; xSysAccount.Phone = txtPhone.Text; xSysAccount.LastLoginTime = DateTime.Now; xSysAccount.LoginNums = 0; xSysAccount.Status = (byte)0; xSysAccount.RealName = txtRealName.Text; //xSysAccount.OrderPop = ""; db.SysAccount.AddObject(xSysAccount); db.SaveChanges(); InitAccount(xSysAccount.AccountID); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (this.txtCode.Text.Trim().Length < 6 || this.txtCode.Text.Trim().Length > 16) { Warning("登录名验证错误!"); return; } if (this.txtpassword.Text.Trim().Length < 6 || this.txtpassword.Text.Trim().Length > 16) { Warning("登录密码验证错误!"); return; } if (!userService.IsUnique(this.txtCode.Text.Trim())) { Warning("登录名已经存在!"); return; } SysAccount account = userService.Get(this.userId); account.Code = this.txtCode.Text.Trim(); account.Name = this.txtName.Text.Trim(); account.PassWord = this.txtpassword.Text.Trim(); account.IsEnabled = this.drpUserType.SelectedValue == "1" ? true : false; userService.Save(); JsAlert("保存成功!", true); this.txtCode.Text = string.Empty; } catch (Exception ex) { JsAlert("保存失败,请稍后再试!"); } }
private ActionResult ViewDetail(SysAccount ob, string msg, AlertMsgType?msgType) { try { if (ob == null) { throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง"); } if (!string.IsNullOrWhiteSpace(msg)) { WidgetAlertModel alert = new WidgetAlertModel() { Message = msg }; if (msgType.HasValue) { alert.Type = msgType.Value; } ViewBag.Alert = alert; } ViewData["optRole"] = uow.Modules.Role.Gets(1, 0, SiteId); ViewData["optRoleCal"] = uow.Modules.Role.Gets(1, 0, 2); return(View("Detail", ob)); } catch (Exception ex) { return(RedirectToAction("Index", new { area = "", controller = "Account", msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
/// <summary> /// 保存修改后的帐号信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, ImageClickEventArgs e) { using (WXDBEntities db = new WXDBEntities()) { int id = UserId; SysAccount xSysAccount = db.SysAccount.Where(a => a.AccountID == id).FirstOrDefault(); xSysAccount.LoginName = txtLoginName.Text; if (!string.IsNullOrEmpty(txtPass.Text)) { xSysAccount.Password = Encrypt.MD5(txtPass.Text); xSysAccount.Status = (byte)1; } xSysAccount.Email = txtMail.Text; xSysAccount.Mobile = txtMobile.Text; xSysAccount.Phone = txtPhone.Text; xSysAccount.RealName = txtRealName.Text; db.SaveChanges(); } jsHint.toUrl("帐号信息" + txtLoginName.Text + "修改成功!", "PasswordEdit.aspx"); }
public ActionResult SetProfile() { int accountId = Session["sid"].Convert2String().ParseInt(); SysAccount ob = uow.Modules.Account.Get(accountId); ob.AccountFirstName = Request.Form["account_firstname"]; ob.AccountLastName = Request.Form["account_lastname"]; ob.AccountEmail = Request.Form["account_email"]; ob.UpdatedBy = CurrentUID; ob.UpdatedDate = CurrentDate; try { if (!ob.IsValid(out string errMsg)) { throw new Exception(errMsg); } bool clearOld = false; string oldAvatar = ob.AccountAvatar; if (Request.Files.Count > 0 && Request.Files["AccountAvatar"] != null && Request.Files["AccountAvatar"].ContentLength > 0) { HttpPostedFileBase uploadedFile = Request.Files["AccountAvatar"]; string FilePath = string.Format("files/avatar/{0}{1}", CurrentDate.ParseString(DateFormat._yyyyMMddHHmmssfff), Path.GetExtension(uploadedFile.FileName)); if (!Directory.Exists(Server.MapPath("~/files"))) { Directory.CreateDirectory(Server.MapPath("~/files")); } if (!Directory.Exists(Server.MapPath("~/files/avatar"))) { Directory.CreateDirectory(Server.MapPath("~/files/avatar")); } uploadedFile.SaveAs(Server.MapPath("~/" + FilePath)); ob.AccountAvatar = FilePath; clearOld = true; } if ((ob.AccountId <= 0 && ob.AccountPassword != Request.Form["account_passwordre"]) || (ob.AccountId > 0 && !string.IsNullOrWhiteSpace(Request.Form["account_password"]) && Request.Form["account_password"] != Request.Form["account_passwordre"])) { throw new Exception("รหัสผ่านไม่ตรงกัน"); } if (ob.AccountId > 0 && !string.IsNullOrWhiteSpace(Request.Form["account_password"])) { ob.AccountPassword = Crypto.HashPassword(Request.Form["account_password"]); } uow.Modules.Account.Set(ob); uow.SaveChanges(); if (clearOld && !string.IsNullOrWhiteSpace(oldAvatar) && IOFile.Exists(Server.MapPath("~/" + oldAvatar))) { IOFile.Delete(Server.MapPath("~/" + oldAvatar)); } return(RedirectToAction("Index", new { area = "", controller = "Home", msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { string msg = ex.GetMessage(); return(ViewProfile(ob, msg, AlertMsgType.Danger)); } }
public async Task <IActionResult> Edit(AccountModel model, SysAccount account) { await _sysUser.SaveChangesAsync(); return(View()); }
public ActionResult SetDetail() { int accountId = Request.Form["account_id"].ParseInt(); int empId = Request.Form["EmpId"].ParseInt(); SysAccount ob = uow.Modules.Account.Get(accountId); if (ob.AccountId <= 0) { ob.AccountUsername = Request.Form["account_username"]; ob.AccountPassword = Request.Form["account_password"]; ob.AccountEmail = Request.Form["account_email"]; ob.CreatedBy = CurrentUID; ob.CreatedDate = CurrentDate; } ob.AccountFirstName = Request.Form["account_firstname"]; ob.AccountLastName = Request.Form["account_lastname"]; ob.FlagStatus = Request.Form["flag_status"].ParseInt(); ob.UpdatedBy = CurrentUID; ob.UpdatedDate = CurrentDate; int roleId = Request.Form["role_id"].ParseInt(); try { if (!ob.IsValid(out string errMsg)) { throw new Exception(errMsg); } if (Request.Files.Count > 0 && Request.Files["AccountAvatar"] != null && Request.Files["AccountAvatar"].ContentLength > 0) { HttpPostedFileBase uploadedFile = Request.Files["AccountAvatar"]; string FilePath = string.Format("files/avatar/{0}{1}", CurrentDate.ParseString(DateFormat._yyyyMMddHHmmssfff), Path.GetExtension(uploadedFile.FileName)); if (!Directory.Exists(Server.MapPath("~/files"))) { Directory.CreateDirectory(Server.MapPath("~/files")); } if (!Directory.Exists(Server.MapPath("~/files/avatar"))) { Directory.CreateDirectory(Server.MapPath("~/files/avatar")); } uploadedFile.SaveAs(Server.MapPath("~/" + FilePath)); ob.AccountAvatar = FilePath; } if ((ob.AccountId <= 0 && ob.AccountPassword != Request.Form["account_passwordre"]) || (ob.AccountId > 0 && !string.IsNullOrWhiteSpace(Request.Form["account_password"]) && Request.Form["account_password"] != Request.Form["account_passwordre"])) { throw new Exception("รหัสผ่านไม่ตรงกัน"); } //if (!ob.FlagSystem) //{ // SysAccountRole roleMapped = ob.AccountId > 0 ? // ((from d in uow.db.SysAccountRole // join r in uow.db.SysRole on d.RoleId equals r.RoleId // where // d.AccountId == ob.AccountId // && r.SiteId == SITE_ID // select d).FirstOrDefault() ?? new SysAccountRole() { SysAccount = ob }) : // new SysAccountRole() { SysAccount = ob }; // roleMapped.RoleId = Request.Form["role_id"].ParseInt(); // if (roleMapped.Id <= 0) { uow.db.SysAccountRole.Add(roleMapped); } // else { uow.db.Entry(roleMapped).State = System.Data.Entity.EntityState.Modified; } //} if (ob.AccountId <= 0) { ob.AccountPassword = Crypto.HashPassword(ob.AccountPassword); } else if (ob.AccountId > 0 && !string.IsNullOrWhiteSpace(Request.Form["account_password"])) { ob.AccountPassword = Crypto.HashPassword(Request.Form["account_password"]); } uow.Modules.Account.Set(ob); // employee.UpdatedDate = DateTime.Now; uow.Modules.Account.SetRole(SiteId, roleId, ob); uow.SaveChanges(); if (empId > 0) { TblEmployee employee = uow.Modules.Employee.Get(empId); employee.AccountId = ob.AccountId; uow.Modules.Employee.Set(employee); } uow.SaveChanges(); return(RedirectToAction("Index", new { area = "", controller = "Account", msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { string msg = ex.GetMessage(); return(ViewDetail(ob, msg, AlertMsgType.Danger)); } }