示例#1
0
        public ActionResult Edit(string id, int locationId, FormCollection collection)
        {
            SystemUser systemUser = new SystemUser();

            systemUser = systemUserRepository.GetUserBySystemUserGuid(id);

            //Check Exists
            if (systemUser == null)
            {
                ViewData["ActionMethod"] = "CreateGet";
                return(View("RecordDoesNotExistError"));
            }

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToLocation(locationId))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }


            SystemUser originalSystemUser = new SystemUser();

            originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(id);

            //CubaBookingAllowanceIndicator with Logging
            bool cubaBookingAllowanceIndicator = false;

            if (originalSystemUser.CubaBookingAllowanceIndicator == true)
            {
                cubaBookingAllowanceIndicator = true;
            }

            //MilitaryAndGovernmentUserFlag with Logging
            bool militaryAndGovernmentUserFlag = false;

            if (originalSystemUser.MilitaryAndGovernmentUserFlag == true)
            {
                militaryAndGovernmentUserFlag = true;
            }

            //Update Item from Form
            try
            {
                UpdateModel(systemUser);
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            //Database Update
            try
            {
                systemUserRepository.Edit(systemUser);

                //Edit SystemUser CubaBookingAllowanceIndicator
                if (cubaBookingAllowanceIndicator != systemUser.CubaBookingAllowanceIndicator)
                {
                    systemUser.VersionNumber = systemUser.VersionNumber + 1;
                    systemUserRepository.EditCubaBookingAllowanceIndicator(systemUser);
                }

                //Edit SystemUser MilitaryAndGovernmentUserFlag
                if (militaryAndGovernmentUserFlag != systemUser.MilitaryAndGovernmentUserFlag)
                {
                    systemUser.VersionNumber = systemUser.VersionNumber + 1;
                    systemUserRepository.EditMilitaryAndGovernmentUserFlag(systemUser);
                }
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/SystemUser.mvc/Edit?id=" + systemUser.SystemUserGuid;
                    return(View("VersionError"));
                }

                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            //Success
            return(RedirectToAction("List"));
        }
        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
            }));
        }