Ejemplo n.º 1
0
        internal async Task <bool> Remove()
        {
            bool returnValue = false;

            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            var folder = _context.FolderDirectories.Where(x => x.FolderDirectoryID == FolderDirectoryID).FirstOrDefault();

            if (folder != null)
            {
                _context.FolderDirectories.Remove(folder);

                await _context.SaveChangesAsync();

                returnValue = true;
            }

            return(returnValue);
        }
Ejemplo n.º 2
0
        public async Task PopulateLists()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            //Populate user roles
            var allRoles = _context.UserRoles.ToList();

            UserRoles = (from r in allRoles
                         orderby r.Description
                         select new UserDetailsViewModelRoles
            {
                Description = r.Description,
                EventCode = r.EventCode,
                UserRoleID = r.UserRoleID,
                Selected = CheckUserHasRole(r.UserRoleID)
            }).ToList();

            //Populate timezone List
            Timezones = (from t in TimeZoneInfo.GetSystemTimeZones()
                         select new SelectListItem
            {
                Value = t.Id,
                Text = t.DisplayName
            }).ToList();
        }
Ejemplo n.º 3
0
        internal async Task PopulateList()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            if (Pagination == null)
            {
                Pagination     = new PaginationViewModel();
                Pagination.Top = 10;
            }

            var list = (from u in _context.Folders.Include(x => x.ParentFolder)
                        where (!string.IsNullOrEmpty(SearchValue) && (u.Description.ToLower().Contains(SearchValue)) || string.IsNullOrEmpty(SearchValue))
                        orderby(u.ParentFolder.Description != null) ? u.ParentFolder.Description : "", u.Description
                        select new FolderListViewModelData
            {
                Description = u.Description,
                FolderID = u.FolderID,
                ParentDescription = (u.ParentFolder != null) ? u.ParentFolder.Description : ""
            });

            Pagination.TotalRecords = list.Count();
            if (!string.IsNullOrEmpty(Pagination.SortBy))
            {
                list = list.OrderByName(Pagination.SortBy, Pagination.Descending);
            }
            ItemList = list.Skip(Pagination.Skip).Take(Pagination.Top).ToList();
        }
Ejemplo n.º 4
0
        internal async Task Save()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            var emailTemplate = _context.EmailTemplates.FirstOrDefault(x => x.EmailTemplateID == EmailTemplateID);

            if (emailTemplate != null)
            {
                emailTemplate.Description  = Description;
                emailTemplate.TemplateBody = TemplateBody;
                emailTemplate.EditDateTime = DateTime.UtcNow;
                emailTemplate.EditUserID   = userHelper.loggedInUserID;

                _context.Update(emailTemplate);

                await _context.SaveChangesAsync();
            }
        }
Ejemplo n.º 5
0
        internal async Task <Guid> Save()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            bool isNew = false;

            if (IsUploadDirectory == true)
            {
                var directories = _context.FolderDirectories.Where(x => x.FolderID == FolderID).ToList();
                foreach (var dir in directories)
                {
                    dir.IsUploadDirectory = false;
                    _context.Update(dir);
                }

                await _context.SaveChangesAsync();
            }

            var folderDir = _context.FolderDirectories.Where(x => x.FolderDirectoryID == FolderDirectoryID).FirstOrDefault();

            if (folderDir == null)
            {
                folderDir = new FolderDirectory();
                isNew     = true;
                folderDir.FolderDirectoryID = Guid.NewGuid();
                folderDir.FolderID          = FolderID;
            }

            folderDir.FolderPath         = FolderPath;
            folderDir.IsUploadDirectory  = IsUploadDirectory;
            folderDir.RequireCredentials = RequireCredentials;
            folderDir.Username           = Username;
            folderDir.Password           = Password;

            if (isNew)
            {
                _context.Add(folderDir);
            }
            else
            {
                _context.Update(folderDir);
            }

            await _context.SaveChangesAsync();

            FolderDirectoryID = folderDir.FolderDirectoryID;

            BackgroundJob.Enqueue <BackgroundJobHelper>(x => x.subRescanDirectories(FolderDirectoryID, null));

            return(FolderDirectoryID);
        }
Ejemplo n.º 6
0
        internal async Task <Guid> Save()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            bool isNew = false;

            var folder = _context.Folders.Where(x => x.FolderID == FolderID).FirstOrDefault();

            if (folder == null)
            {
                folder          = new Folder();
                isNew           = true;
                folder.FolderID = Guid.NewGuid();
            }

            folder.Description    = Description;
            folder.ParentFolderID = (SelectedParentFolderID != Guid.Empty.ToString() && !string.IsNullOrEmpty(SelectedParentFolderID)) ? Guid.Parse(SelectedParentFolderID) : (Guid?)null;

            if (isNew)
            {
                _context.Add(folder);

                //Add logged in user as a share user
                var folderUsr = new FolderUser()
                {
                    AllowDelete  = true,
                    AllowEdit    = true,
                    FolderID     = folder.FolderID,
                    FolderUserID = Guid.NewGuid(),
                    UserID       = userHelper.loggedInUserID
                };

                _context.Add(folderUsr);
            }
            else
            {
                _context.Update(folder);
            }

            await _context.SaveChangesAsync();

            FolderID = folder.FolderID;

            return(FolderID);
        }
Ejemplo n.º 7
0
        internal async Task <Guid> UpdateUserProfile()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            //Save user details
            var user = _context.Users.FirstOrDefault(x => x.UserID == UserID);

            if (user != null)
            {
                //Perform Dup Check
                if (EmailAddress != user.EmailAddress)
                {
                    var userDup = _context.Users.FirstOrDefault(x => ((x.EmailAddress == EmailAddress && x.EmailAddress != null)) && x.IsRemoved == false);
                    if (userDup != null)
                    {
                        errorMessage = "The user email address already exists. Please use a different email address.";
                        return(Guid.Empty);
                    }
                }

                user.DisplayName  = DisplayName;
                user.EmailAddress = EmailAddress;
                user.EditUserID   = userHelper.loggedInUserID;
                user.EditDateTime = DateTime.UtcNow;
                user.FirstName    = FirstName;
                user.Surname      = Surname;
                user.Timezone     = SelectedTimezone;

                _context.Update(user);

                await _context.SaveChangesAsync();

                UserID = user.UserID;

                return(UserID);
            }
            else
            {
                errorMessage = "Profile details not found";
                return(Guid.Empty);
            }
        }
Ejemplo n.º 8
0
        internal async Task PopulateDetail()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            FolderList = LoadFolderList(userHelper, null);
        }
Ejemplo n.º 9
0
 private List <FileListViewModelData> LoadFolderList(UserHelperFunctions userHelper, Guid?parentFolderID = null)
 {
     return((from f in _context.Folders
             join fu in _context.FolderUsers on f.FolderID equals fu.FolderID
             where fu.UserID == userHelper.loggedInUserID && f.ParentFolderID == parentFolderID
             orderby f.Description
             select new { f, fu }).ToList().Select(x => new FileListViewModelData
     {
         Description = x.f.Description,
         AllowDelete = x.fu.AllowDelete,
         AllowEdit = x.fu.AllowEdit,
         FolderID = x.f.FolderID,
         FolderList = LoadFolderList(userHelper, x.f.FolderID)
     }).ToList());
 }
Ejemplo n.º 10
0
        internal async Task <bool> SendForgotPasswordLink()
        {
            bool returnValue = false;

            UserHelperFunctions userHelper = new UserHelperFunctions();

            userHelper._context         = _context;
            userHelper._emailService    = _emailService;
            userHelper._securityOptions = _securityOptions;
            userHelper._user            = _user;
            userHelper.Populate();

            returnValue = await userHelper.SendForgotPasswordLink(Username);

            return(returnValue);
        }
Ejemplo n.º 11
0
        internal async Task <Guid> Save()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            bool isNew = false;

            var folderUser = _context.FolderUsers.Where(x => x.FolderUserID == FolderUserID).FirstOrDefault();

            if (folderUser == null)
            {
                folderUser = new FolderUser();
                isNew      = true;
                folderUser.FolderUserID = Guid.NewGuid();
                folderUser.FolderID     = FolderID;
            }

            folderUser.UserID      = Guid.Parse(SelectedUserID);
            folderUser.AllowDelete = AllowDelete;
            folderUser.AllowEdit   = AllowEdit;

            if (isNew)
            {
                _context.Add(folderUser);
            }
            else
            {
                _context.Update(folderUser);
            }

            await _context.SaveChangesAsync();

            FolderUserID = folderUser.FolderUserID;

            return(FolderUserID);
        }
Ejemplo n.º 12
0
        internal async Task AddNewFolder(string newFolderName, Guid folderID, Guid?parentFolderDirectoryFileID)
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            var folder = _context.FolderUsers.FirstOrDefault(x => x.FolderID == folderID);

            if (folder != null)
            {
                var parentFolder = _context.FolderDirectoryFiles.Include(x => x.FolderDirectory).FirstOrDefault(x => x.FolderDirectoryFileID == parentFolderDirectoryFileID);
                if (parentFolder != null)
                {
                    var dirFile = new FolderDirectoryFile()
                    {
                        FileExtention               = "",
                        FileName                    = newFolderName,
                        FolderDirectoryFileID       = Guid.NewGuid(),
                        FolderDirectoryID           = parentFolder.FolderDirectoryID,
                        FullPath                    = Path.Combine(parentFolder.FullPath, newFolderName),
                        CreatedDate                 = DateTime.UtcNow,
                        IsDirectory                 = true,
                        ParentFolderDirectoryFileID = parentFolderDirectoryFileID
                    };

                    _context.Add(dirFile);

                    await _context.SaveChangesAsync();

                    if (Directory.Exists(Path.Combine(parentFolder.FullPath, newFolderName)) == false)
                    {
                        Directory.CreateDirectory(Path.Combine(parentFolder.FullPath, newFolderName));
                    }
                }
            }
        }
Ejemplo n.º 13
0
        internal async Task PopulateList()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            if (Pagination == null)
            {
                Pagination     = new PaginationViewModel();
                Pagination.Top = 10;
            }

            var list = (from u in _context.FolderDirectories
                        join fu in _context.FolderUsers on u.FolderID equals fu.FolderID
                        join fd in _context.FolderDirectoryFiles on u.FolderDirectoryID equals fd.FolderDirectoryID
                        where u.FolderID == FolderID && fu.UserID == userHelper.loggedInUserID &&
                        fd.ParentFolderDirectoryFileID == ParentFolderDirectoryFileID &&
                        (!string.IsNullOrEmpty(SearchValue) && (fd.FileName.ToLower().Contains(SearchValue)) || string.IsNullOrEmpty(SearchValue))
                        orderby fd.IsDirectory descending, fd.FileName
                        select new FolderFileListViewModelData
            {
                FileName = fd.FileName,
                CreatedDate = fd.CreatedDate.ToString("yyyy/MM/dd HH:mm"),
                FolderDirectoryFileID = fd.FolderDirectoryFileID,
                SizeMB = fd.SizeMB,
                IsUploadDirectory = u.IsUploadDirectory,
                IsDirectory = fd.IsDirectory
            });

            Pagination.TotalRecords = list.Count();
            if (!string.IsNullOrEmpty(Pagination.SortBy))
            {
                list = list.OrderByName(Pagination.SortBy, Pagination.Descending);
            }
            ItemList = list.Skip(Pagination.Skip).Take(Pagination.Top).ToList();
        }
Ejemplo n.º 14
0
        internal async Task RemoveFile(Guid iD)
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            var file = (from u in _context.FolderDirectories
                        join fu in _context.FolderUsers on u.FolderID equals fu.FolderID
                        join fd in _context.FolderDirectoryFiles on u.FolderDirectoryID equals fd.FolderDirectoryID
                        where fd.FolderDirectoryFileID == iD && fu.UserID == userHelper.loggedInUserID &&
                        fu.AllowDelete == true
                        select fd).FirstOrDefault();

            if (file != null)
            {
                if (file.IsDirectory == false)
                {
                    if (System.IO.File.Exists(file.FullPath))
                    {
                        System.IO.File.Delete(file.FullPath);
                    }
                }
                else
                {
                    if (System.IO.Directory.Exists(file.FullPath))
                    {
                        System.IO.Directory.Delete(file.FullPath, true);
                    }
                }

                _context.Remove(file);

                await _context.SaveChangesAsync();
            }
        }
Ejemplo n.º 15
0
        internal async Task <Guid> Save()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            bool isAdd = false;
            var  conf  = _context.SystemConfiguration.Where(x => x.SystemConfigurationID == SystemConfigurationID).FirstOrDefault();

            if (conf == null)
            {
                conf = new SystemConfiguration();
                conf.SystemConfigurationID = Guid.NewGuid();
                conf.CreatedUserID         = userHelper.loggedInUserID;
                conf.CreatedDateTime       = DateTime.UtcNow;
                isAdd = true;
            }

            conf.ConfigValue  = ConfigValue;
            conf.EditUserID   = userHelper.loggedInUserID;
            conf.EditDateTime = DateTime.UtcNow;

            if (isAdd)
            {
                _context.SystemConfiguration.Add(conf);
            }
            else
            {
                _context.SystemConfiguration.Update(conf);
            }

            _context.SaveChanges();

            return(conf.SystemConfigurationID);
        }
Ejemplo n.º 16
0
        internal async Task <bool> ChangePassword()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            bool returnValue = false;

            if (Guid.TryParse(T, out Guid tResult))
            {
                var userToken = _context.UserTemporaryToken.Where(x => x.UserTemporaryTokenID == tResult).FirstOrDefault();
                if (userToken != null)
                {
                    var user = _context.Users.Where(x => x.UserID == userToken.UserID).FirstOrDefault();
                    if (user != null)
                    {
                        var hashedPassword = HashProvider.ComputeHash(Password, HashProvider.HashAlgorithmList.SHA256, _securityOptions.PasswordSalt);

                        user.Password     = hashedPassword;
                        user.IsSuspended  = false;
                        user.LoginTries   = 0;
                        user.EditUserID   = user.UserID;
                        user.EditDateTime = DateTime.UtcNow;
                        user.EditUserID   = userHelper.loggedInUserID;
                        _context.Update(user);

                        await _context.SaveChangesAsync();

                        returnValue = true;
                    }
                }
            }

            return(returnValue);
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> DownloadFile(Guid ID)
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = User
            };

            userHelper.Populate();

            var file = (from fdf in _context.FolderDirectoryFiles
                        join fd in _context.FolderDirectories on fdf.FolderDirectoryID equals fd.FolderDirectoryID
                        join fu in _context.FolderUsers on fd.FolderID equals fu.FolderID
                        where fdf.FolderDirectoryFileID == ID && fu.UserID == userHelper.loggedInUserID
                        select fdf).FirstOrDefault();

            if (file != null)
            {
                if (file.IsDirectory == false)
                {
                    var stream = System.IO.File.OpenRead(file.FullPath);
                    return(new FileStreamResult(stream, file.FileType)
                    {
                        FileDownloadName = file.FileName
                    });
                }
                else
                {
                    BackgroundJob.Enqueue <BackgroundJobHelper>(x => x.CreateZipArchiveSendEmail(file.FolderDirectoryFileID, userHelper.user.EmailAddress, userHelper.user.DisplayName));

                    return(View("DownloadFileQueued"));
                }
            }
            else
            {
                return(new EmptyResult());
            }
        }
Ejemplo n.º 18
0
        internal async Task PopulateList()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            if (Pagination == null)
            {
                Pagination     = new PaginationViewModel();
                Pagination.Top = 10;
            }

            var list = (from u in _context.FolderUsers.Include(x => x.Folder).Include(x => x.User)
                        where u.FolderID == FolderID &&
                        (!string.IsNullOrEmpty(SearchValue) && (u.Folder.Description.ToLower().Contains(SearchValue) || u.User.DisplayName.ToLower().Contains(SearchValue) || u.User.EmailAddress.ToLower().Contains(SearchValue)) || string.IsNullOrEmpty(SearchValue))
                        select new FolderAccessListViewModelData
            {
                FolderUserID = u.FolderUserID,
                Description = u.Folder.Description,
                FolderID = u.FolderID,
                AllowDelete = u.AllowDelete,
                AllowEdit = u.AllowEdit,
                UserDisplayName = u.User.DisplayName,
                UserID = u.UserID
            });

            Pagination.TotalRecords = list.Count();
            if (!string.IsNullOrEmpty(Pagination.SortBy))
            {
                list = list.OrderByName(Pagination.SortBy, Pagination.Descending);
            }
            ItemList = list.Skip(Pagination.Skip).Take(Pagination.Top).ToList();
        }
Ejemplo n.º 19
0
        internal async Task PopulateList()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            if (Pagination == null)
            {
                Pagination     = new PaginationViewModel();
                Pagination.Top = 10;
            }

            var list = (from u in _context.Users
                        where u.IsRemoved == false && (!string.IsNullOrEmpty(SearchValue) && (u.DisplayName.Contains(SearchValue) || u.EmailAddress.Contains(SearchValue)) || string.IsNullOrEmpty(SearchValue))
                        select new UsersListViewModelData
            {
                AllowRemove = (userHelper.loggedInUserID == u.UserID) ? false : true,
                DisplayName = u.DisplayName,
                EmailAddress = u.EmailAddress,
                IsSuspended = u.IsSuspended,
                LoginTries = u.LoginTries,
                UserID = u.UserID
            });

            Pagination.TotalRecords = list.Count();
            if (!string.IsNullOrEmpty(Pagination.SortBy))
            {
                list = list.OrderByName(Pagination.SortBy, Pagination.Descending);
            }
            UserList = list.Skip(Pagination.Skip).Take(Pagination.Top).ToList();
        }
Ejemplo n.º 20
0
        public async Task <Guid> Save()
        {
            UserHelperFunctions userHelper = new UserHelperFunctions()
            {
                _context         = _context,
                _emailService    = _emailService,
                _securityOptions = _securityOptions,
                _user            = _user
            };

            userHelper.Populate();

            bool   isNew        = false;
            bool   isWasRemoved = false;
            string tempPassword = "";

            PublicEnums.EmailTemplateList emailTemplate = PublicEnums.EmailTemplateList.NTF_REGISTRATION_WELCOME_CUSTOM;

            //Save user details
            var user = _context.Users.FirstOrDefault(x => x.UserID == UserID);

            if (user == null)
            {
                //Check user not deleted before
                user = _context.Users.FirstOrDefault(x => ((x.EmailAddress == EmailAddress && x.EmailAddress != null)) && x.IsRemoved == true);
                if (user == null)
                {
                    //Perform dup-check
                    user = _context.Users.FirstOrDefault(x => ((x.EmailAddress == EmailAddress && x.EmailAddress != null)) && x.IsRemoved == false);
                    if (user == null)
                    {
                        user                 = new User();
                        isNew                = true;
                        user.UserID          = Guid.NewGuid();
                        user.IsSuspended     = false;
                        user.LoginTries      = 0;
                        user.CreatedUserID   = userHelper.loggedInUserID;
                        user.CreatedDateTime = DateTime.UtcNow;
                        user.IsRemoved       = false;

                        tempPassword = HelperFunctions.GeneratePassword(8);
                        if (!string.IsNullOrEmpty(_tmpPassword))
                        {
                            tempPassword = _tmpPassword;
                        }

                        user.Password = HashProvider.ComputeHash(tempPassword, HashProvider.HashAlgorithmList.SHA256, _securityOptions.PasswordSalt);
                        _tmpPassword  = tempPassword;
                    }
                    else
                    {
                        errorMessage = "The user email address already exists. Find the existing user first and edit their details";
                        return(Guid.Empty);
                    }
                }
                else
                {
                    tempPassword = HelperFunctions.GeneratePassword(8);
                    if (!string.IsNullOrEmpty(_tmpPassword))
                    {
                        tempPassword = _tmpPassword;
                    }

                    user.Password = HashProvider.ComputeHash(tempPassword, HashProvider.HashAlgorithmList.SHA256, _securityOptions.PasswordSalt);
                    _tmpPassword  = tempPassword;

                    user.IsRemoved = false;
                    isWasRemoved   = true;
                }
            }

            user.DisplayName  = DisplayName;
            user.EmailAddress = EmailAddress;
            user.IsSuspended  = IsSuspended;
            user.LoginTries   = (IsSuspended == false) ? 0 : user.LoginTries;
            user.EditUserID   = userHelper.loggedInUserID;
            user.EditDateTime = DateTime.UtcNow;
            user.FirstName    = FirstName;
            user.Surname      = Surname;
            user.Timezone     = SelectedTimezone;

            if (isNew)
            {
                _context.Add(user);
            }
            else
            {
                _context.Update(user);
            }

            if (isNew || isWasRemoved)
            {
                #region  Send new user registration email

                if (!string.IsNullOrEmpty(EmailAddress))
                {
                    emailTemplate = PublicEnums.EmailTemplateList.NTF_REGISTRATION_WELCOME_CUSTOM;

                    var variables = new Dictionary <string, PropertyMetaData>
                    {
                        { "HostUrl", new PropertyMetaData {
                              Type = typeof(string), Value = _securityOptions.WebsiteHostUrl
                          } },
                        { "DisplayName", new PropertyMetaData {
                              Type = typeof(string), Value = DisplayName
                          } },
                        { "Password", new PropertyMetaData {
                              Type = typeof(string), Value = tempPassword
                          } },
                        { "Username", new PropertyMetaData {
                              Type = typeof(string), Value = EmailAddress
                          } }
                    };

                    await _emailService.SendEmailAsync(new List <string>() { EmailAddress }, "Welcome", emailTemplate, variables, _user);
                }
                #endregion
            }

            await ClearUserRoles(user.UserID);
            await AddSelectedUserRoles(user.UserID);

            await _context.SaveChangesAsync();

            UserID = user.UserID;

            return(UserID);
        }