public static bool ForgotPassword(HuntingEntities dataContext, AclUser aclUser) { try { aclUser.EmailCode = Guid.NewGuid().ToString(); aclUser.EmailCodeExpire = DateTime.Now.AddHours(Settings.Default.EmailCodeExpireHours); EmailContext.CreateForgottenEmail(dataContext, aclUser); dataContext.SaveChanges(); return(true); } catch (Exception exception) { logger.Error(exception, "ForgotPassword({0})", aclUser != null ? aclUser.Email : "N/A"); return(false); } }
public static bool InviteUser(HuntingEntities dataContext, Territory territory, string email, string name, AclUser sender) { var isNewUser = false; var lowerUserName = email.Trim().ToLower(); var aclUser = dataContext.AclUsers.FirstOrDefault(item => item.IsDeleted == false && item.Email == lowerUserName); if (aclUser == null) { if (string.IsNullOrWhiteSpace(name)) { return(false); } aclUser = new AclUser() { AccountTypeEx = AccountTypeEnum.Standard, Email = email, EmailCode = Guid.NewGuid().ToString(), Fullname = name, MaxTerritoryCount = 0, SysCreated = DateTime.Now, SysEditor = sender.Id, SysUpdated = DateTime.Now, }; dataContext.AclUsers.Add(aclUser); EmailContext.CreateInviteEmail(dataContext, aclUser, sender); isNewUser = true; } if (territory.TerritoryUsers.Any(item => item.AclUserId == aclUser.Id)) { return(true); } var territoryUser = new TerritoryUser() { AclUser = aclUser, UserRoleEx = isNewUser ? TerritoryUserRoleEnum.Invited : TerritoryUserRoleEnum.Member, }; territory.TerritoryUsers.Add(territoryUser); dataContext.SaveChanges(); return(true); }
public static int?Update(HuntingEntities dataContext, AclUser updateItem, AclUserUpdateModel model, int userId) { try { if (model.IsCreate) { updateItem = new AclUser() { SysCreated = DateTime.Now, EmailCode = Guid.NewGuid().ToString(), }; dataContext.AclUsers.Add(updateItem); } updateItem.Email = model.Email; updateItem.AccountTypeEx = model.AccountType; updateItem.Fullname = model.Fullname; if (updateItem.AccountTypeEx == AccountTypeEnum.Admin) { updateItem.MaxTerritoryCount = -1; } else if (updateItem.AccountTypeEx == AccountTypeEnum.Standard) { updateItem.MaxTerritoryCount = 0; } else { updateItem.MaxTerritoryCount = int.Parse(model.MaxTerritoryCount); } updateItem.SysEditor = userId; updateItem.SysUpdated = DateTime.Now; if (model.IsCreate) { EmailContext.CreateRegistrationEmail(dataContext, updateItem, userId); } dataContext.SaveChanges(); return(updateItem.Id); } catch (Exception exception) { logger.Error(exception, "Update"); } return(null); }