public static void CloseAllTasksForUserChangingStatusFromOnHold(ApplicationDbContext db, Guid appUserId) { List <UserTask> activeTasksForThisUser = UserTaskHelpers.GetTasksByReference(db, appUserId); foreach (UserTask activeTaskForThisUser in activeTasksForThisUser) { UserTaskHelpers.UpdateEntityStatus(activeTaskForThisUser.UserTaskId, EntityStatusEnum.Closed); } }
public static DashboardView GetDashboardViewLogin(ApplicationDbContext db, IPrincipal user) { AppUser appUser = AppUserHelpers.GetAppUser(db, user); //initialise the view DashboardView dashboardView = new DashboardView(); //get the campaigns and listings for this user List <Campaign> campaignsForUser = CampaignHelpers.GetAllCampaignsForUser(db, appUser.AppUserId, false); dashboardView.CampaignList = campaignsForUser; List <Campaign> campaignsDashboardList = CampaignHelpers.GetAllDashboardFilteredCampaigns(db, appUser.AppUserId); dashboardView.CampaignDashboardList = campaignsDashboardList; List <RequirementListing> requirementListingsForUser = RequirementListingHelpers.GetAllRequirementListingsForUser(db, appUser.AppUserId, false); dashboardView.RequirementListingList = requirementListingsForUser; List <RequirementListing> requirementListingDashboardList = RequirementListingHelpers.GetAllDashboardFilteredRequirementListings(db, appUser.AppUserId); dashboardView.RequirementListingDashboardList = requirementListingDashboardList; List <AvailableListing> availableListingsForUser = AvailableListingHelpers.GetAllAvailableListingsForUser(db, appUser.AppUserId, false); dashboardView.AvailableListingList = availableListingsForUser; List <AvailableListing> availableListingDashboardList = AvailableListingHelpers.GetAllDashboardFilteredAvailableListings(db, appUser.AppUserId); dashboardView.AvailableListingDashboardList = availableListingDashboardList; List <Offer> offersForUser = OfferHelpers.GetAllOffersForUser(db, appUser.AppUserId, false); dashboardView.OfferList = offersForUser; List <Order> ordersForUser = OrderHelpers.GetAllOrdersForUser(db, appUser.AppUserId, false); dashboardView.OrderList = ordersForUser; //get listings for admin areas if this user is not a 'User' - i.e. is Manager, Admin etc. if (user.Identity.GetCurrentUserRole() != "User") { List <UserTask> tasksForUser = UserTaskHelpers.GetUserTasksForUser(db, appUser.AppUserId); //LSLSLS get list of 'actions' once written dashboardView.UserTaskList = tasksForUser; } return(dashboardView); }
public static List <UserTaskView> GetUserTasksForUserView(ApplicationDbContext db, Guid appUserId) { List <UserTaskView> userTasksForUserView = new List <UserTaskView>(); List <UserTask> userTasksForUser = UserTaskHelpers.GetUserTasksForUser(db, appUserId); foreach (UserTask userTaskForUser in userTasksForUser) { AppUser appUser = null; Branch branch = null; switch (userTaskForUser.TaskType) { case TaskTypeEnum.UserOnHold: appUser = AppUserHelpers.GetAppUser(db, userTaskForUser.ReferenceKey); break; case TaskTypeEnum.BranchOnHold: branch = BranchHelpers.GetBranch(db, userTaskForUser.ReferenceKey); break; } UserTaskView userTaskForUserView = new UserTaskView() { UserTaskId = userTaskForUser.UserTaskId, TaskType = userTaskForUser.TaskType, TaskDescription = userTaskForUser.TaskDescription, AppUserReference = appUser, BranchReference = branch, CreatedOn = userTaskForUser.CreatedOn, CreatedBy = AppUserHelpers.GetAppUser(db, userTaskForUser.CreatedBy), EntityStatus = userTaskForUser.EntityStatus }; userTasksForUserView.Add(userTaskForUserView); } return(userTasksForUserView); }
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); } }
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); } }