public ActionResult Add(string key, string json) { var msg = new JsonMessage(false, "Thêm mới dữ liệu thành công."); try { if (key == Keyapi) { var date = DateTime.Now.TotalSeconds(); var objitem = JsonConvert.DeserializeObject <AgencyItem>(json); var obj = new DN_Agency { IsDelete = false, IsLock = false, IsOut = false, CreateDate = date, WalletValue = 10000000, CashOut = 0, }; obj = UpdateBase(obj, objitem); _da.Add(obj); _da.Save(); if (objitem.GroupID > 0) { _da.InsertDNModule(objitem.GroupID, obj.ID); } var saltKey = FDIUtils.CreateSaltKey(5); var sha1PasswordHash = FDIUtils.CreatePasswordHash(objitem.Pass, saltKey); var user = new DN_Users { UserId = Guid.NewGuid(), PasswordSalt = saltKey, Password = sha1PasswordHash, UserName = objitem.UserName, LoweredUserName = obj.Name, Email = obj.Email, Address = obj.Address, AgencyID = obj.ID, Mobile = obj.Phone, IsApproved = true, IsLockedOut = false, CreateDate = date, IsDeleted = false }; _daUserDa.Add(user); _daUserDa.Save(); var role = new DN_Roles { RoleId = Guid.NewGuid(), RoleName = "Admin", LoweredRoleName = "admin", AgencyID = obj.ID, Description = "Quản trị" }; _darRoleDa.Add(role); var dnUsersInRoles = new DN_UsersInRoles { UserId = user.UserId, AgencyID = obj.ID, DateCreated = date, IsDelete = false }; role.DN_UsersInRoles.Add(dnUsersInRoles); _darRoleDa.Save(); } } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được thêm mới."; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="mobile">UserName</param> /// <param name="mobile">SĐT3G</param> /// <param name="pass">Mật khẩu</param> /// <param name="address">Địa chỉ</param> /// <returns></returns> public ActionResult Addapp(string mobile, string pass, string address, string name, string email) { int gid = 3; var objr = new DNUserAppItem { UserName = mobile, EnterprisesID = 3, Status = 0 }; try { if (string.IsNullOrEmpty(mobile)) { return(Json(new BaseResponse <AgencyItem>() { Erros = true, Message = "Số điện thoại không được để trống" })); } if (string.IsNullOrEmpty(pass)) { return(Json(new BaseResponse <AgencyItem>() { Erros = true, Message = "Mật khẩu không được để trống" })); } if (_daUserDa.CheckUserName(mobile, true)) { return(Json(new BaseResponse <AgencyItem>() { Erros = true, Message = "Số điện thoại đã tồn tại" })); } var daten = DateTime.Now; var date = daten.TotalSeconds(); var obj = new DN_Agency { Address = address, FullName = name, Name = mobile, Phone = mobile, GroupID = gid, EnterpriseID = 3, IsShow = true, IsDelete = false, IsLock = false, IsOut = false, IsFdi = false, CreateDate = date, WalletValue = 0, CashOut = 0, Email = email }; _da.Add(obj); _da.Save(); if (obj.GroupID > 0) { _da.InsertDNModule(obj.GroupID, obj.ID); } var saltKey = FDIUtils.CreateSaltKey(5); var sha1PasswordHash = FDIUtils.CreatePasswordHash(pass, saltKey); var user = new DN_Users { UserId = Guid.NewGuid(), PasswordSalt = saltKey, Password = sha1PasswordHash, UserName = mobile, LoweredUserName = name, Email = pass, Address = address, AgencyID = obj.ID, Mobile = mobile, IsApproved = true, IsLockedOut = false, CreateDate = date, IsDeleted = false, IsAgency = true }; _daUserDa.Add(user); _daUserDa.Save(); var role = new DN_Roles { RoleId = Guid.NewGuid(), RoleName = "Admin", LoweredRoleName = "admin", AgencyID = obj.ID, Description = "Quản trị" }; _darRoleDa.Add(role); var dnUsersInRoles = new DN_UsersInRoles { UserId = user.UserId, AgencyID = obj.ID, DateCreated = date, IsDelete = false }; role.DN_UsersInRoles.Add(dnUsersInRoles); _darRoleDa.Save(); var result = new BaseResponse <AgencyItem>() { Erros = false, }; return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } return(Json(new BaseResponse <AgencyItem>() { Erros = false }, JsonRequestBehavior.AllowGet)); }