Exemple #1
0
        public async Task ChangeEntityStatus(TKey id, EntityStatusEnum status)
        {
            var entity = await _repository.GetById(id);

            entity.Status = status;
            await _repository.Update(entity);
        }
Exemple #2
0
        public static ISqlMapper CreateMapper(EntityStatusEnum status, ISQLConvert converter)
        {
            ISqlMapper mapper = null;

            switch (status)
            {
            case EntityStatusEnum.Insert:
                mapper = new InsertMapper(converter);
                break;

            case EntityStatusEnum.Delete:
                mapper = new DeleteByIDMapper(converter);
                break;

            case EntityStatusEnum.Update:
                mapper = new UpdateByIDMapper(converter);
                break;

            case EntityStatusEnum.InsertOrUpdate:
                mapper = new InsertOrUpdateMapper(converter);
                break;
            }

            return(mapper);
        }
Exemple #3
0
 public void Excluir()
 {
     if (Status == EntityStatusEnum.Ativa)
     {
         Status = EntityStatusEnum.Inativa;
     }
 }
Exemple #4
0
        public void ConvertStatus(string status)
        {
            switch (status.ToLower())
            {
            case "insert":
                Status = EntityStatusEnum.Insert;
                break;

            case "update":
                Status = EntityStatusEnum.Update;
                break;

            case "delete":
                Status = EntityStatusEnum.Delete;
                break;

            case "insertorupdate":
                Status = EntityStatusEnum.InsertOrUpdate;
                break;

            default:
                Status = EntityStatusEnum.Insert;
                break;
            }
        }
        public static BranchUser UpdateBranchUserStatus(BranchUser branchUser, EntityStatusEnum newEntityStatus, Guid appUserId)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            BranchUser           updateBranchUser = UpdateBranchUserStatus(db, branchUser, newEntityStatus, appUserId);

            db.Dispose();
            return(updateBranchUser);
        }
Exemple #6
0
        public static AppUser UpdateEntityStatus(Guid appUserId, EntityStatusEnum entityStatus)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            AppUser appUser         = UpdateEntityStatus(db, appUserId, entityStatus);

            db.Dispose();
            return(appUser);
        }
Exemple #7
0
        public static UserTask UpdateEntityStatus(Guid userTaskId, EntityStatusEnum entityStatus)
        {
            ApplicationDbContext db       = new ApplicationDbContext();
            UserTask             userTask = UpdateEntityStatus(db, userTaskId, entityStatus);

            db.Dispose();
            return(userTask);
        }
Exemple #8
0
        public static Branch UpdateEntityStatus(Guid branchId, EntityStatusEnum entityStatus)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            Branch branch           = UpdateEntityStatus(db, branchId, entityStatus);

            db.Dispose();
            return(branch);
        }
        Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                ApplicationUser user = UserManager.FindByEmail(model.Email);
                //validate user status - if not active then give appropriate message and reject - NOTE "Awaiting organisation details" is fine to go through as it allows the logged in user to add details
                EntityStatusEnum appUserStatus = AppUserHelpers.GetAppUserEntityStatus(user);
                switch (appUserStatus)
                {
                case EntityStatusEnum.OnHold:
                    ModelState.AddModelError("", "This user is currently on hold.  You will need to contact your account administrator to active your account.");
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    return(View(model));

                case EntityStatusEnum.Inactive:
                    ModelState.AddModelError("", "This user is currently inactive.  You will need to re-register or contact your account administrator.");
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    return(View(model));

                case EntityStatusEnum.Rejected:
                    ModelState.AddModelError("", "This user is currently rejected.  You will need to contact your account administrator to active your account.");
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    return(View(model));

                case EntityStatusEnum.PasswordResetRequired:
                    return(RedirectToAction("ChangePassword", "Manage"));
                }
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                ApplicationUser user = UserManager.FindByEmail(model.Email);
                //validate the user is not on-hold
                if (!AppUserHelpers.IsAppUserActive(user))
                {
                    EntityStatusEnum appUserStatus = AppUserHelpers.GetAppUserEntityStatus(user);
                    switch (appUserStatus)
                    {
                    case EntityStatusEnum.Inactive:
                        ModelState.AddModelError("", "This user is currently inactive.  You will need to re-register or contact your account administrator");
                        break;

                    case EntityStatusEnum.OnHold:
                        ModelState.AddModelError("", "This user is currently on hold.  You will need to contact your account administrator to active your account");
                        break;
                    }
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    return(View(model));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Exemple #11
0
        /// <summary>
        /// 创建文章
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="title"></param>
        /// <param name="desc"></param>
        /// <param name="content"></param>
        public Article(long userId, string title, string desc, string content, List <Category> categories)
        {
            Verification(title, desc, content);
            VerifyCategories(categories);
            SetId();

            _bloggerId  = userId;
            Content     = content;
            ArticleInfo = new ArticleInfo(title, desc);
            Status      = EntityStatusEnum.Available;
            EditCategory(categories);
            _createTime = DateTime.Now;

            AddDomainEvent(new CreateArticleEvent(_bloggerId, Id));
        }
Exemple #12
0
 public static EntityState ConvertState(EntityStatusEnum status)
 {
     switch (status)
     {
         case EntityStatusEnum.Added:
             return EntityState.Added;
         case EntityStatusEnum.Deleted:
             return EntityState.Deleted;
         case EntityStatusEnum.Detached:
             return EntityState.Detached;
         case EntityStatusEnum.Modified:
             return EntityState.Modified;
         default:
             return EntityState.Unchanged;
     }
 }
Exemple #13
0
        public static List <Notification> GetNotificationsForOrganisationFromUser(ApplicationDbContext db, IPrincipal user, bool getHistory)
        {
            AppUser          appUser = AppUserHelpers.GetAppUser(db, user);
            EntityStatusEnum status  = EntityStatusEnum.Active;

            if (getHistory)
            {
                status = EntityStatusEnum.Inactive;
            }

            List <Notification> list = (from n in db.Notifications
                                        where (n.OrganisationId == appUser.OrganisationId && n.EntityStatus == status)
                                        orderby n.RecordChangeBy ascending
                                        select n).Distinct().ToList();

            return(list);
        }
Exemple #14
0
        public static List <UserTask> GetUserTasksForOrganisationFromUser(ApplicationDbContext db, IPrincipal user, bool getHistory)
        {
            AppUser          appUser = AppUserHelpers.GetAppUser(db, user);
            EntityStatusEnum status  = EntityStatusEnum.Active;

            if (getHistory)
            {
                status = EntityStatusEnum.Inactive;
            }

            List <UserTask> list = (from ut in db.UserTasks
                                    where (ut.OrganisationId == appUser.OrganisationId && ut.EntityStatus == status)
                                    orderby ut.RecordChangeBy ascending
                                    select ut).Distinct().ToList();

            return(list);
        }
        public static SelectList EntityStatusEnumsForUsersDropDown(EntityStatusEnum status)
        {
            var enumList = (from EntityStatusEnum bt in Enum.GetValues(typeof(EntityStatusEnum))
                            select new
            {
                Id = bt,
                Name = EnumHelpers.GetDescription((EntityStatusEnum)bt)
            });

            SelectList list = new SelectList(enumList, "Id", "Name", status);

            //remove the non AppUser values...
            list = new SelectList(list
                                  .Where(x => (x.Value != "Rejected") && (x.Value != "Closed") && (x.Value != "Removed"))
                                  .ToList(),
                                  "Value",
                                  "Text",
                                  status);

            return(list);
        }
Exemple #16
0
        public static Branch UpdateEntityStatus(ApplicationDbContext db, Guid branchId, EntityStatusEnum entityStatus)
        {
            Branch branch = BranchHelpers.GetBranch(db, branchId);

            branch.EntityStatus    = entityStatus;
            db.Entry(branch).State = EntityState.Modified;
            db.SaveChanges();

            return(branch);
        }
Exemple #17
0
        public static AppUser UpdateAppUserRoleAndEntityStatus(ApplicationDbContext db, Guid updatedUserId, UserRoleEnum?role, EntityStatusEnum status, IPrincipal updatedByUser)
        {
            AppUser updatedAppUser = GetAppUser(db, updatedUserId);

            if (role.HasValue)
            {
                updatedAppUser.UserRole = role.Value;
            }
            updatedAppUser.EntityStatus   = status;
            updatedAppUser.RecordChange   = RecordChangeEnum.StatusChange;
            updatedAppUser.RecordChangeBy = GetAppUserIdFromUser(updatedByUser);
            updatedAppUser.RecordChangeOn = DateTime.Now;

            db.Entry(updatedAppUser).State = EntityState.Modified;
            db.SaveChanges();

            //create Tasks for changes in status to On-Hold
            if (status == EntityStatusEnum.OnHold)
            {
                UserTasksHelpers.CreateUserTask(db, TaskTypeEnum.UserOnHold, "New user on hold, awaiting administrator activation", updatedAppUser.AppUserId, updatedAppUser.LoginEmail, updatedAppUser.OrganisationId, updatedByUser);
            }

            return(updatedAppUser);
        }
Exemple #18
0
        public static Branch UpdateBranch(ApplicationDbContext db, Guid branchId, Guid companyId, BusinessTypeEnum businessType, string branchName, string addressLine1, string addressLine2, string addressLine3, string addressTownCity, string addressCounty, string addressPostcode, string telephoneNumber, string email, string contactName, PrivacyLevelEnum privacyLevel, EntityStatusEnum entityStatus)
        {
            Branch branch = GetBranch(db, branchId);

            branch.CompanyId       = companyId;
            branch.BranchName      = branchName;
            branch.BusinessType    = businessType;
            branch.AddressLine1    = addressLine1;
            branch.AddressLine2    = addressLine2;
            branch.AddressLine3    = addressLine3;
            branch.AddressTownCity = addressTownCity;
            branch.AddressCounty   = addressCounty;
            branch.AddressPostcode = addressPostcode;
            branch.TelephoneNumber = telephoneNumber;
            branch.Email           = email;
            branch.ContactName     = contactName;
            branch.PrivacyLevel    = privacyLevel;
            branch.EntityStatus    = entityStatus;

            db.Entry(branch).State = EntityState.Modified;
            db.SaveChanges();

            return(branch);
        }
Exemple #19
0
        public static Branch UpdateBranch(Guid branchId, Guid companyId, BusinessTypeEnum businessType, string branchName, string addressLine1, string addressLine2, string addressLine3, string addressTownCity, string addressCounty, string addressPostcode, string telephoneNumber, string email, string contactName, PrivacyLevelEnum privacyLevel, EntityStatusEnum entityStatus)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            Branch branch           = UpdateBranch(db, branchId, companyId, businessType, branchName, addressLine1, addressLine2, addressLine3, addressTownCity, addressCounty, addressPostcode, telephoneNumber, email, contactName, privacyLevel, entityStatus);

            db.Dispose();
            return(branch);
        }
Exemple #20
0
        public static Branch CreateBranch(ApplicationDbContext db, Guid companyId, BusinessTypeEnum businessType, string branchName, string addressLine1, string addressLine2, string addressLine3, string addressTownCity, string addressCounty, string addressPostcode, string telephoneNumber, string email, string contactName, PrivacyLevelEnum privacyLevel, EntityStatusEnum entityStatus)
        {
            Branch branch = new Branch()
            {
                BranchId        = Guid.NewGuid(),
                CompanyId       = companyId,
                BusinessType    = businessType,
                BranchName      = branchName,
                AddressLine1    = addressLine1,
                AddressLine2    = addressLine2,
                AddressLine3    = addressLine3,
                AddressTownCity = addressTownCity,
                AddressCounty   = addressCounty,
                AddressPostcode = addressPostcode,
                TelephoneNumber = telephoneNumber,
                Email           = email,
                ContactName     = contactName,
                PrivacyLevel    = privacyLevel,
                EntityStatus    = entityStatus
            };

            db.Branches.Add(branch);
            db.SaveChanges();

            return(branch);
        }
        public static bool UpdateUsersFromUserAdminView(ApplicationDbContext db, List <UserAdminView> userAdminViewForUser, IPrincipal user)
        {
            //Get logged in user details for Task creation (if required)
            AppUser loggedInUser = AppUserHelpers.GetAppUser(db, user);

            try
            {
                List <Guid> userChangedFromAdminList = new List <Guid>();

                foreach (UserAdminView userAdminView in userAdminViewForUser)
                {
                    //Get original appUser record so that we can compare previous and current entity status'
                    AppUser          appUser = AppUserHelpers.GetAppUser(db, userAdminView.AppUserId);
                    EntityStatusEnum previousEntityStatus = appUser.EntityStatus;

                    //Update the AppUser record (except Current Branch as that was done in real time)
                    appUser = AppUserHelpers.UpdateAppUserExcludingCurrentBranchField(db,
                                                                                      userAdminView.AppUserId,
                                                                                      userAdminView.FirstName,
                                                                                      userAdminView.LastName,
                                                                                      userAdminView.AppUserEntityStatus,
                                                                                      userAdminView.PrivacyLevel);

                    //if change of status from on-hold - anything then look for outstanding task and set to closed
                    if (userAdminView.AppUserEntityStatus != EntityStatusEnum.OnHold && previousEntityStatus == EntityStatusEnum.OnHold)
                    {
                        UserTaskHelpers.CloseAllTasksForUserChangingStatusFromOnHold(db, appUser.AppUserId);
                    }

                    //If change of status to on-hold then create a Task
                    if (userAdminView.AppUserEntityStatus == EntityStatusEnum.OnHold && previousEntityStatus != EntityStatusEnum.OnHold)
                    {
                        UserTaskHelpers.CreateUserTask(TaskTypeEnum.UserOnHold, "User on hold, awaiting administrator/manager activation", appUser.AppUserId, loggedInUser.AppUserId, EntityStatusEnum.Active);
                    }

                    //If change of status from Active then check outstanding actions/tasks and reassign/create new tasks/actions???
                    //CURRENTLY - don't do anything for ACTIONS as these are specific and TASKS will be assigned at ADMIN level also so don't do anything here at present

                    //If change of role from ADMIN to something else then tasks will need to be re-assigned - THIS IS DONE IN /Data/SetUserToNewRole

                    List <Guid> userSetToAdminList = new List <Guid>();
                    //Update the User Role on each Branch
                    foreach (UserAdminRelatedBranchesView relatedBranch in userAdminView.RelatedBranches)
                    {
                        //just keep a list of the user's we have set to Admin as within the UpdateBranchUserRole, if a role is set to Admin on 1 user, then that user on every branch is set to Admin, so we don't want to set it back
                        Guid toAdminResult = userSetToAdminList.Find(x => x == relatedBranch.AppUserId);

                        if (toAdminResult == Guid.Empty)
                        {
                            BranchUserHelpers.UpdateBranchUserRole(db, relatedBranch.BranchUserId, relatedBranch.UserRole);
                            if (relatedBranch.UserRole == UserRoleEnum.Admin)
                            {
                                userSetToAdminList.Add(relatedBranch.AppUserId);
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return(false);
            }
        }
Exemple #22
0
        public static AppUser CreateAppUser(string firstName, string lastName, Guid currentBranchId, EntityStatusEnum entityStatus, string loginEmail, PrivacyLevelEnum privacyLevel, UserRoleEnum userRole)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            AppUser appUser         = CreateAppUser(db, firstName, lastName, currentBranchId, entityStatus, loginEmail, privacyLevel, userRole);

            db.Dispose();
            return(appUser);
        }
Exemple #23
0
        public static Notification UpdateEntityStatus(ApplicationDbContext db, Guid notificationId, EntityStatusEnum entityStatus, IPrincipal user)
        {
            Notification notification = GetNotification(db, notificationId);

            notification.EntityStatus   = entityStatus;
            notification.RecordChange   = RecordChangeEnum.StatusChange;
            notification.RecordChangeOn = DateTime.Now;
            notification.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user);

            db.Entry(notification).State = EntityState.Modified;
            db.SaveChanges();

            return(notification);
        }
Exemple #24
0
        public static Notification UpdateNotificationEntityStatus(ApplicationDbContext db, Guid?notificationId, Notification action, EntityStatusEnum newStatus, IPrincipal user)
        {
            if (action == null)
            {
                action = NotificationHelpers.GetNotification(db, notificationId.Value);
            }

            action.EntityStatus   = newStatus;
            action.RecordChange   = RecordChangeEnum.StatusChange;
            action.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user);
            action.RecordChangeOn = DateTime.Now;

            db.Entry(action).State = EntityState.Modified;
            db.SaveChanges();

            return(action);
        }
Exemple #25
0
        public static List <AppUser> GetAppUsersForOrganisationWithEntityStatus(ApplicationDbContext db, Guid organisationId, EntityStatusEnum status)
        {
            List <AppUser> users = (from au in db.AppUsers
                                    where (au.OrganisationId == organisationId && au.EntityStatus == status)
                                    select au).Distinct().ToList();

            return(users);
        }
Exemple #26
0
        public static AppUser UpdateAppUserExcludingCurrentBranchField(ApplicationDbContext db, Guid appUserId, string firstName, string lastName, EntityStatusEnum entityStatus, PrivacyLevelEnum privacyLevel)
        {
            AppUser appUser = GetAppUser(db, appUserId);

            appUser.FirstName    = firstName;
            appUser.LastName     = lastName;
            appUser.EntityStatus = entityStatus;
            appUser.PrivacyLevel = privacyLevel;

            db.Entry(appUser).State = EntityState.Modified;
            db.SaveChanges();

            return(appUser);
        }
Exemple #27
0
        public static AppUser UpdateAppUserExcludingCurrentBranchField(Guid appUserId, string firstName, string lastName, EntityStatusEnum entityStatus, PrivacyLevelEnum privacyLevel)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            AppUser appUser         = UpdateAppUserExcludingCurrentBranchField(db, appUserId, firstName, lastName, entityStatus, privacyLevel);

            db.Dispose();
            return(appUser);
        }
Exemple #28
0
        public static AppUser UpdateEntityStatus(ApplicationDbContext db, Guid appUserId, EntityStatusEnum entityStatus)
        {
            AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId);

            appUser.EntityStatus    = entityStatus;
            db.Entry(appUser).State = EntityState.Modified;
            db.SaveChanges();

            return(appUser);
        }
Exemple #29
0
 public static AppUser UpdateAppUserRoleAndEntityStatus(ApplicationDbContext db, IPrincipal updatedUser, UserRoleEnum?role, EntityStatusEnum status, IPrincipal updatedByUser)
 {
     return(UpdateAppUserRoleAndEntityStatus(db, GetAppUserIdFromUser(updatedUser), role, status, updatedByUser));
 }
        public static bool UpdateBranchesFromBranchAdminView(ApplicationDbContext db, List <BranchAdminView> branchesAdminView, IPrincipal user)
        {
            //Get logged in user details for Task creation (if required)
            AppUser loggedInUser = AppUserHelpers.GetAppUser(db, user);

            try
            {
                foreach (BranchAdminView branchAdminVeiw in branchesAdminView)
                {
                    //Get original branch record so that we can compare previous and current entity status'
                    Branch           branch = BranchHelpers.GetBranch(db, branchAdminVeiw.BranchId);
                    EntityStatusEnum previousEntityStatus = branch.EntityStatus;

                    //Update branch
                    branch = BranchHelpers.UpdateBranch(db,
                                                        branchAdminVeiw.BranchId,
                                                        branchAdminVeiw.CompanyId,
                                                        branchAdminVeiw.BusinessType,
                                                        branchAdminVeiw.BranchName,
                                                        branchAdminVeiw.AddressLine1,
                                                        branchAdminVeiw.AddressLine2,
                                                        branchAdminVeiw.AddressLine3,
                                                        branchAdminVeiw.AddressTownCity,
                                                        branchAdminVeiw.AddressCounty,
                                                        branchAdminVeiw.AddressPostcode,
                                                        branchAdminVeiw.TelephoneNumber,
                                                        branchAdminVeiw.Email,
                                                        branchAdminVeiw.ContactName,
                                                        branchAdminVeiw.PrivacyLevel,
                                                        branchAdminVeiw.EntityStatus);

                    //if change of status from on-hold - anything then look for outstanding task and set to closed
                    if (branchAdminVeiw.EntityStatus != EntityStatusEnum.OnHold && previousEntityStatus == EntityStatusEnum.OnHold)
                    {
                        List <UserTask> activeTasksForThisBranch = UserTaskHelpers.GetUserTasksForBranch(db, branch.BranchId);

                        foreach (UserTask activeTaskForThisBranch in activeTasksForThisBranch)
                        {
                            UserTaskHelpers.UpdateEntityStatus(activeTaskForThisBranch.UserTaskId, EntityStatusEnum.Closed);
                        }
                    }

                    //If change of status to on-hold then create a Task
                    if (branchAdminVeiw.EntityStatus == EntityStatusEnum.OnHold && previousEntityStatus != EntityStatusEnum.OnHold)
                    {
                        UserTaskHelpers.CreateUserTask(TaskTypeEnum.BranchOnHold, "New branch on hold, awaiting administrator activation", branch.BranchId, loggedInUser.AppUserId, EntityStatusEnum.Active);
                    }

                    //Update Users link with Branch
                    foreach (BranchAdminViewCompanyUser companyUser in branchAdminVeiw.RelatedCompanyUsers)
                    {
                        //Try to find the user
                        BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, companyUser.AppUserId, branchAdminVeiw.BranchId, branchAdminVeiw.CompanyId);

                        //Now check if user is checked in list then ensure it is on branchUser, else remove if it is on branchUser
                        if (companyUser.LinkedToThisBranch)
                        {
                            //if company user linked but not on BranchUser, add to BranchUser
                            if (branchUser == null)
                            {
                                BranchUserHelpers.CreateBranchUser(db, companyUser.AppUserId, branchAdminVeiw.BranchId, branchAdminVeiw.CompanyId, UserRoleEnum.User, EntityStatusEnum.Active);
                            }
                            //if company user linked but not ACTIVE on BranchUser
                            else if (branchUser.EntityStatus != EntityStatusEnum.Active)
                            {
                                BranchUserHelpers.UpdateBranchUserStatus(db, branchUser, EntityStatusEnum.Active, companyUser.AppUserId);
                            }
                        }
                        else
                        {
                            //if company user not linked but is on BranchUser, remove from BranchUser by setting status to Inactive
                            if (branchUser != null)
                            {
                                BranchUserHelpers.UpdateBranchUserStatus(db, branchUser, EntityStatusEnum.Inactive, companyUser.AppUserId);
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return(false);
            }
        }
Exemple #31
0
        public static AppUser CreateAppUser(ApplicationDbContext db, string firstName, string lastName, Guid currentBranchId, EntityStatusEnum entityStatus, string loginEmail, PrivacyLevelEnum privacyLevel, UserRoleEnum userRole)
        {
            bool superUser = false;
            bool adminUser = false;

            if (userRole == UserRoleEnum.SuperUser)
            {
                superUser = true;
            }
            if (userRole == UserRoleEnum.Admin)
            {
                adminUser = true;
            }

            AppUser appUser = new AppUser()
            {
                AppUserId       = Guid.NewGuid(),
                FirstName       = firstName,
                LastName        = lastName,
                CurrentBranchId = currentBranchId,
                EntityStatus    = entityStatus,
                PrivacyLevel    = privacyLevel,
                LoginEmail      = loginEmail,
                SuperUser       = superUser,
                AdminUser       = adminUser
            };

            db.AppUsers.Add(appUser);

            //Create initial settings values from the settings template
            AppUserSettingsHelpers.CreateAppUserSettingsForNewUser(db, appUser.AppUserId, userRole);

            db.SaveChanges();

            return(appUser);
        }