public ActionResult ValidateTeam(Team team)
        {
            try
            {
                //Check Access Rights
                if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
                {
                    return(PartialView("Error", "You Do Not Have Access to Teams. Please Contact an Administrator"));
                }

                //Validate Team data against Table
                if (!ModelState.IsValid)
                {
                    TeamTypeRepository teamTypeRepository = new TeamTypeRepository();
                    SelectList         teamTypesList      = new SelectList(teamTypeRepository.GetAllTeamTypes().ToList(), "TeamTypeCode", "TeamTypeDescription");
                    ViewData["TeamTypes"] = teamTypesList;

                    TablesDomainHierarchyLevelRepository tablesDomainHierarchyLevelRepository = new TablesDomainHierarchyLevelRepository();
                    SelectList hierarchyTypesList = new SelectList(tablesDomainHierarchyLevelRepository.GetDomainHierarchies(groupName).ToList(), "HierarchyLevelTableName", "HierarchyLevelTableName");
                    ViewData["HierarchyTypes"] = hierarchyTypesList;

                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "TeamDetailsScreen", team),
                        message = "ValidationError",
                        success = false
                    }));
                }

                TeamSystemUsersVM teamUsersScreen = new TeamSystemUsersVM();
                teamUsersScreen.Team = team;
                if (team.TeamId > 0)
                {
                    teamUsersScreen.SystemUsers = teamWizardRepository.GetTeamSystemUsers(team.TeamId);
                }
                else
                {
                    // for Team with no Systemusers
                    List <spDDAWizard_SelectTeamSystemUsers_v1Result> systemUsers = new List <spDDAWizard_SelectTeamSystemUsers_v1Result>();
                    teamUsersScreen.SystemUsers = systemUsers;
                }
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "TeamUsersScreen", teamUsersScreen),
                    message = "Success",
                    success = true
                }));
            }
            catch (Exception ex)
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", ex.Message),
                    message = "UnhandledError",
                    success = false
                }));
            }
        }
        public ActionResult ValidateSystemUser(SystemUserWizardVM systemUserWizardViewModel)
        {
            SystemUser systemUser = new SystemUser();

            systemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserWizardViewModel.SystemUser.SystemUserGuid);
            systemUserWizardViewModel.SystemUser = systemUser;

            if (systemUserWizardViewModel.SystemUserLocation == null)
            {
                ModelState.Clear();
                ModelState.AddModelError("SystemUser.LocationName", "Location Required");

                //Validation Error
                string msg = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        msg += error.ErrorMessage;
                    }
                }

                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "SystemUserDetailsScreen", systemUserWizardViewModel),
                    message = "ValidationError: " + msg,
                    success = false
                }));
            }

            //Validate SystemUser data against Table
            if (!ModelState.IsValid)
            {
                //not needed
            }

            //SystemUser + List of SystemUser's Teams
            SystemUserTeamsVM systemUserTeamsViewModel = new SystemUserTeamsVM();

            //Add Systemuser
            systemUserTeamsViewModel.SystemUser = systemUser;

            //Add SystemUser's Teams
            SystemUserTeamRepository systemUserTeamRepository             = new SystemUserTeamRepository();
            List <spDDAWizard_SelectSystemUserTeams_v1Result> systemUsers = new List <spDDAWizard_SelectSystemUserTeams_v1Result>();

            systemUserTeamsViewModel.Teams = systemUserWizardRepository.GetSystemUserTeams(systemUser.SystemUserGuid);

            //Return Page with list of SystemUser's Teams
            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "SystemUserTeamsScreen", systemUserTeamsViewModel),
                message = "Success",
                success = true
            }));
        }
        public ActionResult ConfirmChangesScreen(SystemUserWizardVM updatedSystemUser)
        {
            //Messages that will be displayed to User
            WizardMessages wizardMessages = new WizardMessages();

            //Model to Store Original Item for Comparison
            SystemUserWizardVM originalSystemUserWizardViewModel = new SystemUserWizardVM();

            //Location
            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
            SystemUserLocation           originalSystemUserLocation   = new SystemUserLocation();

            originalSystemUserLocation = systemUserLocationRepository.GetSystemUserLocation(updatedSystemUser.SystemUser.SystemUserGuid);
            if (originalSystemUserLocation != null)
            {
                originalSystemUserWizardViewModel.SystemUserLocation = originalSystemUserLocation;
            }

            //System User
            SystemUser originalSystemUser = new SystemUser();

            originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(updatedSystemUser.SystemUser.SystemUserGuid);
            if (originalSystemUser != null)
            {
                originalSystemUserWizardViewModel.SystemUser = originalSystemUser;
            }

            //GDSs
            SystemUserGDSRepository systemUserGDSRepository = new SystemUserGDSRepository();
            List <fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result> originalSystemuserGDSs = new List <fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result>();

            originalSystemuserGDSs = systemUserGDSRepository.GetSystemUserGDSs(updatedSystemUser.SystemUser.SystemUserGuid).ToList();
            if (originalSystemuserGDSs != null)
            {
                originalSystemUserWizardViewModel.SystemUserGDSs = originalSystemuserGDSs;
            }

            //ExternalSystemLoginSystemUserCountries
            ExternalSystemLoginRepository externalSystemLoginRepository = new ExternalSystemLoginRepository();
            List <ExternalSystemLoginSystemUserCountry> originalExternalSystemLoginSystemUserCountries = externalSystemLoginRepository.GetBackOfficeIdentifiers(updatedSystemUser.SystemUser.SystemUserGuid);

            if (originalExternalSystemLoginSystemUserCountries != null && originalExternalSystemLoginSystemUserCountries.Count > 0)
            {
                originalSystemUserWizardViewModel.ExternalSystemLoginSystemUserCountries = originalExternalSystemLoginSystemUserCountries;
            }

            systemUserWizardRepository.BuildSystemUserChangeMessages(wizardMessages, originalSystemUserWizardViewModel, updatedSystemUser);

            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "ConfirmChangesScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
예제 #4
0
        public ActionResult ConfirmChangesScreen(LocationWizardVM updatedLocationViewModel)
        {
            //Make sure we have minimum data
            if (updatedLocationViewModel.Location == null)
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", "No Location Information"),
                    message = "Error",
                    success = false
                }));
            }

            //get LocationId
            int locationId = updatedLocationViewModel.Location.LocationId;

            //Object to store messages for Display
            WizardMessages wizardMessages = new WizardMessages();

            //Editing a Location
            if (locationId > 0)
            {
                //Get Original Information from Databse
                Location originalLocation = new Location();
                originalLocation = locationRepository.GetLocation(locationId);

                AddressRepository addressRepository = new AddressRepository();
                Address           originalAddress   = new Address();
                int addressId = updatedLocationViewModel.Address.AddressId;
                originalAddress = addressRepository.GetAddress(addressId);

                LocationWizardVM originalLocationViewModel = new LocationWizardVM();
                originalLocationViewModel.Location = originalLocation;
                originalLocationViewModel.Address  = originalAddress;

                //Compare Original Information to Submitted Information to Create a List of Messages about changes
                locationWizardRepository.BuildLocationChangeMessages(wizardMessages, originalLocationViewModel, updatedLocationViewModel);
            }
            else
            {
                //Adding an Item - Create a List of Messages about changes
                locationWizardRepository.BuildLocationChangeMessages(wizardMessages, null, updatedLocationViewModel);
            }

            //Return List of Changes to user for Final Confirmation
            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "ConfirmChangesScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
        public ActionResult ConfirmChangesScreen(TeamWizardVM updatedTeam)
        {
            WizardMessages wizardMessages = new WizardMessages();

            if (updatedTeam.Team.TeamId > 0)
            {
                Team originalTeam = new Team();
                originalTeam = teamRepository.GetTeam(updatedTeam.Team.TeamId);
                teamRepository.EditGroupForDisplay(originalTeam);

                teamWizardRepository.BuildTeamChangeMessages(wizardMessages, originalTeam, updatedTeam);
            }
            else
            {
                teamWizardRepository.BuildTeamChangeMessages(wizardMessages, null, updatedTeam);
            }

            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "ConfirmChangesScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
        public ActionResult CommitChanges(TeamWizardVM teamChanges)
        {
            Team team = new Team();

            team = teamChanges.Team;

            WizardMessages wizardMessages = new WizardMessages();

            try{
                UpdateModel(team);
            }
            catch
            {
                //Validation Error
                string msg = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        msg += error.ErrorMessage;
                    }
                }
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                    message = msg,
                    success = false
                }));
            }
            //Editing A Team
            if (team.TeamId > 0)
            {
                try
                {
                    teamWizardRepository.UpdateTeam(team);
                    wizardMessages.AddMessage("Team Details successfully updated", true);
                }
                catch (SqlException ex)
                {
                    //If there is error we will continue, but store error to return to user

                    //Versioning Error
                    if (ex.Message == "SQLVersioningError")
                    {
                        wizardMessages.AddMessage("Team Detail was not updated. Another user has already changed this Team.", false);
                    }
                    else //Other Error
                    {
                        LogRepository logRepository = new LogRepository();
                        logRepository.LogError(ex.Message);

                        wizardMessages.AddMessage("Team Details were not updated, please check Event Log for details", false);
                        wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                    }
                }
            }
            else //Adding A Team
            {
                try
                {
                    int teamId = teamWizardRepository.AddTeam(team);
                    team             = teamRepository.GetTeam(teamId);
                    teamChanges.Team = team;
                    wizardMessages.AddMessage("Team added successfully", true);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("Team was not added, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);

                    //If we cannot add a Team , we cannot continue, so return error to User
                    return(Json(new
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                        message = "DBError",
                        success = false
                    }));
                }
            }
            //If we have added a Team successfully, or edited a Team (successfully or unsuccessfully), we continue to add SystemUsers/ClientSubUnits
            try
            {
                wizardMessages = teamWizardRepository.UpdateTeamSystemUsers(teamChanges, wizardMessages);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                wizardMessages.AddMessage("Team SystemUser were not changed, please check Event Log for details", false);
                wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
            }
            try
            {
                wizardMessages = teamWizardRepository.UpdateTeamClientSubUnits(teamChanges, wizardMessages);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                wizardMessages.AddMessage("Team ClientSubUnits were not changed, please check Event Log for details", false);
                wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
            }
            return(Json(new
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
        public ActionResult DeleteTeam(Team team)
        {
            //Check Exists
            if (team == null)
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", "Team does not Exist"),
                    message = "NoRecordError",
                    success = false
                }));
            }
            //Check AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToTeam(team.TeamId))
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", "You do not have access to this Team"),
                    message = "NoAccessError",
                    success = false
                }));
            }
            //Delete Item
            try
            {
                teamRepository.Delete(team);
            }
            catch (SqlException ex)
            {
                if (ex.Message == "SQLVersioningError")
                {
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "VersionError", null),
                        message = "VersionError",
                        success = false
                    }));
                }
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", ex.Message),
                    message = "DBError",
                    success = false
                }));
            }

            WizardMessages wizardMessages = new WizardMessages();

            wizardMessages.AddMessage("Team has been successfully deleted.", true);

            //Item Deleted - Return response
            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
        public ActionResult CommitChanges(SystemUserWizardVM systemUserChanges)
        {
            SystemUserLocation systemUserLocation = new SystemUserLocation();

            systemUserLocation = systemUserChanges.SystemUserLocation;


            WizardMessages wizardMessages = new WizardMessages();

            try
            {
                TryUpdateModel(systemUserChanges.SystemUserLocation, "SystemUserLocation");
            }
            catch
            {
                //Validation Error
                string msg = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        msg += error.ErrorMessage;
                    }
                }
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                    message = msg,
                    success = false
                }));
            }


            //Editing A SystemUser Location
            try
            {
                SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
                SystemUserLocation           originalSystemUserLocation   = new SystemUserLocation();
                originalSystemUserLocation = systemUserLocationRepository.GetSystemUserLocation(systemUserChanges.SystemUser.SystemUserGuid);
                if (originalSystemUserLocation == null)
                {
                    systemUserLocationRepository.Add(systemUserLocation);
                    wizardMessages.AddMessage("User's Location successfully updated", true);
                }
                else
                {
                    if (originalSystemUserLocation.LocationId != systemUserChanges.SystemUserLocation.LocationId)
                    {
                        systemUserLocationRepository.Update(systemUserLocation);
                        wizardMessages.AddMessage("User's Location successfully updated", true);
                    }
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Location was not updated. Another user has already changed this Location.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Location was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }


            //Editing Default Profile Identifier
            try
            {
                SystemUserRepository systemUserRepository = new SystemUserRepository();
                SystemUser           originalSystemUser   = new SystemUser();
                originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserChanges.SystemUser.SystemUserGuid);

                if (originalSystemUser.DefaultProfileIdentifier == null)
                {
                    originalSystemUser.DefaultProfileIdentifier = false;
                }
                if (originalSystemUser.DefaultProfileIdentifier != systemUserChanges.SystemUser.DefaultProfileIdentifier)
                {
                    wizardMessages.AddMessage("User's Default Profile successfully updated", true);
                    systemUserRepository.EditDefaultProfileIdentifier(systemUserChanges.SystemUser);
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Default Profile was not updated. Another user has already changed this.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Default Profile was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }

            //Editing Restricted Flag
            try
            {
                SystemUserRepository systemUserRepository = new SystemUserRepository();
                SystemUser           originalSystemUser   = new SystemUser();
                originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserChanges.SystemUser.SystemUserGuid);

                if (originalSystemUser.RestrictedFlag == null)
                {
                    originalSystemUser.RestrictedFlag = false;
                }
                if (originalSystemUser.RestrictedFlag != systemUserChanges.SystemUser.RestrictedFlag)
                {
                    wizardMessages.AddMessage("User's Restricted Flag successfully updated", true);
                    systemUserRepository.EditRestrictedFlag(systemUserChanges.SystemUser);
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Restricted Flag was not updated. Another user has already changed this.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Restricted Flag was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }

            //Editing Cuba Booking Allowed Identifier
            try
            {
                SystemUserRepository systemUserRepository = new SystemUserRepository();
                SystemUser           originalSystemUser   = new SystemUser();
                originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserChanges.SystemUser.SystemUserGuid);

                if (originalSystemUser.CubaBookingAllowanceIndicator == null)
                {
                    originalSystemUser.CubaBookingAllowanceIndicator = false;
                }

                if (originalSystemUser.CubaBookingAllowanceIndicator != systemUserChanges.SystemUser.CubaBookingAllowanceIndicator)
                {
                    wizardMessages.AddMessage("User's Cuba Booking Allowed successfully updated", true);
                    systemUserRepository.EditCubaBookingAllowanceIndicator(systemUserChanges.SystemUser);
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Cuba Booking Allowed was not updated. Another user has already changed this.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Cuba Booking Allowed was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }


            //ExternalSystemLoginSystemUserCountries
            ExternalSystemLoginRepository externalSystemLoginRepository = new ExternalSystemLoginRepository();
            List <ExternalSystemLoginSystemUserCountry> originalExternalSystemLoginSystemUserCountries = externalSystemLoginRepository.GetBackOfficeIdentifiers(systemUserChanges.SystemUser.SystemUserGuid);

            if (originalExternalSystemLoginSystemUserCountries != null && originalExternalSystemLoginSystemUserCountries.Count == 0)
            {
                originalExternalSystemLoginSystemUserCountries = null;
            }

            if (originalExternalSystemLoginSystemUserCountries != systemUserChanges.ExternalSystemLoginSystemUserCountries)
            {
                string systemUserGuid = systemUserChanges.SystemUser.SystemUserGuid;
                try
                {
                    externalSystemLoginRepository.AddBackOfficeIdentifiers(systemUserGuid, systemUserChanges.ExternalSystemLoginSystemUserCountries);
                    wizardMessages.AddMessage("User's Back Office Identifiers successfully updated", true);
                }
                catch (SqlException ex)
                {
                    //Versioning Error
                    if (ex.Message == "SQLVersioningError")
                    {
                        wizardMessages.AddMessage("User's BackOffice Identifier was not updated. Another user has already changed this item.", false);
                    }
                    else                     //Other Error
                    {
                        LogRepository logRepository = new LogRepository();
                        logRepository.LogError(ex.Message);

                        wizardMessages.AddMessage("User's BackOffice Identifier was not updated, please check Event Log for details", false);
                        wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                    }
                }
            }

            //we continue to add Teams
            try
            {
                wizardMessages = systemUserWizardRepository.UpdateSystemUserTeams(systemUserChanges, wizardMessages);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                wizardMessages.AddMessage("User's Teams were not changed, please check Event Log for details", false);
                wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
            }

            //we continue to add GDSs
            if (systemUserChanges.GDSChanged)
            {
                try
                {
                    wizardMessages = systemUserWizardRepository.UpdateSystemUserGDSs(systemUserChanges, wizardMessages);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's GDS settings were not changed, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }
            return(Json(new
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
예제 #9
0
        public ActionResult CommitChanges(LocationWizardVM locationChanges)
        {
            Location location = new Location();

            location = locationChanges.Location;
            string msg = "";

            Address address = new Address();

            address = locationChanges.Address;

            WizardMessages wizardMessages = new WizardMessages();

            try
            {
                UpdateModel(location);
            }
            catch
            {
                //Validation Error
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        msg += error.ErrorMessage;
                    }
                }
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                    message = msg,
                    success = false
                }));
            }
            //Editing A Location
            if (location.LocationId > 0)
            {
                //Access Rights to this Location
                if (!rolesRepository.HasWriteAccessToLocation(location.LocationId))
                {
                    msg = "You do not have access to this item";
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                        message = msg,
                        success = false
                    }));
                }


                try
                {
                    locationWizardRepository.UpdateLocationAddress(location, address);
                    wizardMessages.AddMessage("Location Details successfully updated", true);
                }
                catch (SqlException ex)
                {
                    //If there is error we will continue, but store error to return to user

                    //Versioning Error
                    if (ex.Message == "SQLVersioningError")
                    {
                        wizardMessages.AddMessage("Location was not updated. Another user has already changed this Location.", false);
                    }
                    else //Other Error
                    {
                        LogRepository logRepository = new LogRepository();
                        logRepository.LogError(ex.Message);

                        wizardMessages.AddMessage("Location Details were not updated, please check Event Log for details", false);
                        wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                    }
                }
            }
            else //Adding A LOcation
            {
                //Access Rights to Locations
                if (!hierarchyRepository.AdminHasDomainWriteAccess("Location"))
                {
                    msg = "You do not have access to this item";
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                        message = msg,
                        success = false
                    }));
                }
                try
                {
                    int locationId = locationWizardRepository.AddLocationAddress(location, address);
                    location = locationRepository.GetLocation(locationId);
                    locationChanges.Location = location;
                    wizardMessages.AddMessage("Location added successfully", true);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("Location was not added, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);

                    //If we cannot add a Team , we cannot continue, so return error to User
                    return(Json(new
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                        message = "DBError",
                        success = false
                    }));
                }
            }
            //If we have added a Location successfully, or edited a Location (successfully or unsuccessfully),
            //we continue to make SystemUsers changes
            if (locationChanges.SystemUsersAdded != null || locationChanges.SystemUsersRemoved != null)
            {
                try
                {
                    wizardMessages = locationWizardRepository.UpdateLocationSystemUsers(locationChanges, wizardMessages);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("Team SystemUser were not changed, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }
            //return to user
            return(Json(new
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
예제 #10
0
        public ActionResult ValidateLocation(LocationWizardVM locationWizardViewModel)
        {
            int locationId = 0;

            if (locationWizardViewModel.Location != null)
            {
                locationId = locationWizardViewModel.Location.LocationId;
            }

            //Validate Team data against Table
            if (!ModelState.IsValid)
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }

                //Need to repopulate List
                MappingQualityRepository mappingQualityRepository = new MappingQualityRepository();
                locationWizardViewModel.MappingQualityCodes = new SelectList(mappingQualityRepository.GetAllMappingQualities().ToList(), "MappingQualityCode", "MappingQualityCode", locationWizardViewModel.Address.MappingQualityCode);;
                locationWizardViewModel.SystemUserCount     = locationWizardRepository.GetLocationSystemUsers(locationId).Count;

                //StateProvince SelectList
                StateProvinceRepository stateProvinceRepository = new StateProvinceRepository();
                locationWizardViewModel.StateProvinces = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(locationWizardViewModel.Location.CountryCode).ToList(), "StateProvinceCode", "Name", locationWizardViewModel.Address.StateProvinceCode);

                //Validation Error - retrun to Details Screen
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "LocationDetailsScreen", locationWizardViewModel),
                    message = "ValidationError (" + n + ")",
                    success = false
                }));
            }

            //Location
            Location location = new Location();

            location = locationWizardViewModel.Location;
            LocationSystemUsersVM locationUsersScreen = new LocationSystemUsersVM();

            locationUsersScreen.Location = locationWizardViewModel.Location;

            // Systemusers
            List <spDDAWizard_SelectLocationSystemUsers_v1Result> systemUsers = new List <spDDAWizard_SelectLocationSystemUsers_v1Result>();

            systemUsers = locationWizardRepository.GetLocationSystemUsers(location.LocationId);
            locationUsersScreen.SystemUsers = systemUsers;

            //Show Location's systemUsers
            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "LocationUsersScreen", locationUsersScreen),
                message = "Success",
                success = true
            }));
        }
예제 #11
0
        public ActionResult DeleteLocation(Location location)
        {
            //Access Rights to Locations
            if (!hierarchyRepository.AdminHasDomainWriteAccess("Location"))
            {
                return(PartialView("Error", "You do not have access to this item"));
            }

            //Check Exists
            if (location == null)
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", "Location does not Exist"),
                    message = "NoRecordError",
                    success = false
                }));
            }
            //Access Rights to this Location
            if (!rolesRepository.HasWriteAccessToLocation(location.LocationId))
            {
                return(PartialView("Error", "You do not have access to this item"));
            }

            //Delete Item
            try
            {
                locationRepository.Delete(location);
            }
            catch (SqlException ex)
            {
                if (ex.Message == "SQLVersioningError")
                {
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "VersionError", null),
                        message = "VersionError",
                        success = false
                    }));
                }
                if (ex.Message == "SQLDeleteError")
                {
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "DeleteError", null),
                        message = "DeleteError",
                        success = false
                    }));
                }
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", ex.Message),
                    message = "DBError",
                    success = false
                }));
            }

            WizardMessages wizardMessages = new WizardMessages();

            wizardMessages.AddMessage("Location has been successfully deleted.", true);

            //Item Deleted - Return response
            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }