コード例 #1
0
        public ActionResult LocationDetailsScreen(int locationId = 0)
        {
            if (!hierarchyRepository.AdminHasDomainWriteAccess("Location"))
            {
                return(PartialView("Error", "You do not have access to this item"));
            }

            Location location = new Location();
            Address  address  = new Address();

            CountryRepository countryRepository = new CountryRepository();

            if (locationId > 0)
            {
                location = locationRepository.GetLocation(locationId);

                //Check Exists
                if (location == null)
                {
                    return(PartialView("Error", "Location Does Not Exist"));
                }

                //get Address
                address = locationRepository.GetLocationAddress(locationId);
                AddressRepository addressRepository = new AddressRepository();
                addressRepository.EditForDisplay(address);

                //add linked information
                locationRepository.EditForDisplay(location);
            }

            LocationWizardVM locationWizardViewModel = new LocationWizardVM();

            locationWizardViewModel.Location        = location;
            locationWizardViewModel.Address         = address;
            locationWizardViewModel.SystemUserCount = locationWizardRepository.GetLocationSystemUsers(locationId).Count;

            MappingQualityRepository mappingQualityRepository = new MappingQualityRepository();

            if (locationWizardViewModel.Address != null)
            {
                locationWizardViewModel.MappingQualityCodes = new SelectList(mappingQualityRepository.GetAllMappingQualities().ToList(), "MappingQualityCode", "MappingQualityCode", locationWizardViewModel.Address.MappingQualityCode);
            }
            else
            {
                locationWizardViewModel.MappingQualityCodes = new SelectList(mappingQualityRepository.GetAllMappingQualities().ToList(), "MappingQualityCode", "MappingQualityCode");
            }

            //StateProvince SelectList
            StateProvinceRepository stateProvinceRepository = new StateProvinceRepository();

            locationWizardViewModel.StateProvinces = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(location.CountryCode).ToList(), "StateProvinceCode", "Name", address.StateProvinceCode);

            return(PartialView("LocationDetailsScreen", locationWizardViewModel));
        }
コード例 #2
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
            }));
        }
コード例 #3
0
        //Update Location SystemUsers
        public WizardMessages UpdateLocationSystemUsers(LocationWizardVM locationChanges, WizardMessages wizardMessages)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            Location location = new Location();

            location = locationChanges.Location;
            bool changesExist = false;

            // Create the xml document container
            XmlDocument    doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("LocationSystemUsers");

            doc.AppendChild(root);

            SystemUserRepository systemUserRepository = new SystemUserRepository();

            if (locationChanges.SystemUsersAdded != null)
            {
                if (locationChanges.SystemUsersAdded.Count > 0)
                {
                    changesExist = true;
                    //xml = xml + "<SystemUsersAdded>";
                    XmlElement xmlSystemUsersAdded = doc.CreateElement("SystemUsersAdded");

                    foreach (SystemUser item in locationChanges.SystemUsersAdded)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        string systemUserName = systemUser.FirstName + (item.MiddleName != "" ? item.MiddleName + " " : "") + systemUser.LastName;
                        //xml = xml + "<SystemUser>";
                        //xml = xml + "<SystemUserName>" + systemUserName + "</SystemUserName>";
                        //xml = xml + "<SystemUserGuid>" + item.SystemUserGuid + "</SystemUserGuid>";
                        //xml = xml + "</SystemUser>";

                        XmlElement xmlSystemUser = doc.CreateElement("SystemUser");
                        xmlSystemUsersAdded.AppendChild(xmlSystemUser);

                        XmlElement xmlSystemUserName = doc.CreateElement("SystemUserName");
                        xmlSystemUserName.InnerText = systemUserName;
                        xmlSystemUser.AppendChild(xmlSystemUserName);

                        XmlElement xmlSystemUserGuid = doc.CreateElement("SystemUserGuid");
                        xmlSystemUserGuid.InnerText = item.SystemUserGuid;
                        xmlSystemUser.AppendChild(xmlSystemUserGuid);
                    }
                    root.AppendChild(xmlSystemUsersAdded);
                    //xml = xml + "</SystemUsersAdded>";
                }
            }
            if (locationChanges.SystemUsersRemoved != null)
            {
                if (locationChanges.SystemUsersRemoved.Count > 0)
                {
                    changesExist = true;
                    //xml = xml + "<SystemUsersRemoved>";
                    XmlElement xmlSystemUsersRemoved = doc.CreateElement("SystemUsersRemoved");

                    foreach (SystemUser item in locationChanges.SystemUsersRemoved)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        string systemUserName = systemUser.FirstName + (item.MiddleName != "" ? item.MiddleName + " " : "") + systemUser.LastName;
                        //xml = xml + "<SystemUser>";
                        //xml = xml + "<SystemUserName>" + systemUserName + "</SystemUserName>";
                        //xml = xml + "<SystemUserGuid>" + item.SystemUserGuid + "</SystemUserGuid>";
                        //xml = xml + "</SystemUser>";

                        XmlElement xmlSystemUser = doc.CreateElement("SystemUser");
                        xmlSystemUsersRemoved.AppendChild(xmlSystemUser);

                        XmlElement xmlSystemUserName = doc.CreateElement("SystemUserName");
                        xmlSystemUserName.InnerText = systemUserName;
                        xmlSystemUser.AppendChild(xmlSystemUserName);

                        XmlElement xmlSystemUserGuid = doc.CreateElement("SystemUserGuid");
                        xmlSystemUserGuid.InnerText = item.SystemUserGuid;
                        xmlSystemUser.AppendChild(xmlSystemUserGuid);
                    }
                    root.AppendChild(xmlSystemUsersRemoved);
                    //xml = xml + "</SystemUsersRemoved>";
                }
            }
            //xml = xml + "</LocationSystemUsers>";
            if (changesExist)
            {
                var output = (from n in db.spDDAWizard_UpdateLocationSystemUsers_v1(
                                  location.LocationId,
                                  System.Xml.Linq.XElement.Parse(doc.OuterXml),
                                  adminUserGuid)
                              select n).ToList();

                foreach (spDDAWizard_UpdateLocationSystemUsers_v1Result message in output)
                {
                    wizardMessages.AddMessage(message.MessageText.ToString(), (bool)message.Success);
                }
            }
            return(wizardMessages);
        }
コード例 #4
0
        //Compare two Locations and return a list of messages about changes
        public WizardMessages BuildLocationChangeMessages(WizardMessages wizardMessages, LocationWizardVM originalLocationViewModel, LocationWizardVM updatedLocationViewModel)
        {
            /*Location*/
            LocationRepository locationRepository = new LocationRepository();
            Location           originalLocation   = new Location();
            Location           updatedLocation    = new Location();

            //If Editing a Location
            if (originalLocationViewModel != null)
            {
                originalLocation = originalLocationViewModel.Location;
                locationRepository.EditForDisplay(originalLocation);
            }
            updatedLocation = updatedLocationViewModel.Location;
            locationRepository.EditForDisplay(updatedLocation);

            if (originalLocation.LocationId == 0)
            {
                wizardMessages.AddMessage("A new Location \"" + updatedLocation.LocationName + "\" has been added.", true);
            }
            else
            {
                if (originalLocation.LocationName != updatedLocation.LocationName)
                {
                    wizardMessages.AddMessage("Location Name will be updated to \"" + updatedLocation.LocationName + "\".", true);
                }

                if (originalLocation.CountryCode != updatedLocation.CountryCode)
                {
                    wizardMessages.AddMessage("Location Country will be updated to \"" + updatedLocation.CountryRegionName + "\".", true);
                }
                if (originalLocation.CountryRegionId != updatedLocation.CountryRegionId)
                {
                    wizardMessages.AddMessage("Location Country Region will be updated to \"" + updatedLocation.CountryRegionName + "\".", true);
                }
            }

            /*Address*/
            AddressRepository addressRepository = new AddressRepository();
            Address           originalAddress   = new Address();
            Address           updatedAddress    = new Address();



            if (originalLocationViewModel != null)
            {
                originalAddress = originalLocationViewModel.Address;
                if (originalAddress != null)
                {
                    addressRepository.EditForDisplay(originalAddress);
                }
            }
            updatedAddress = updatedLocationViewModel.Address;
            addressRepository.EditForDisplay(updatedAddress);

            if (originalAddress == null)
            {
                //need this for Comparisons to work
                originalAddress = new Address();
            }

            if (originalAddress.FirstAddressLine != updatedAddress.FirstAddressLine || originalAddress.SecondAddressLine != updatedAddress.SecondAddressLine)
            {
                wizardMessages.AddMessage("Address Lines will be updated", true);
            }

            if (originalAddress.CityName != updatedAddress.CityName)
            {
                wizardMessages.AddMessage("City will be updated to \"" + updatedAddress.CityName + "\".", true);
            }
            if (originalAddress.StateProvinceCode != updatedAddress.StateProvinceCode)
            {
                wizardMessages.AddMessage("State/Province will be updated to \"" + updatedAddress.StateProvinceName + "\".", true);
            }
            if (originalAddress.CountyName != updatedAddress.CountyName)
            {
                wizardMessages.AddMessage("County will be updated to \"" + updatedAddress.CountyName + "\".", true);
            }
            if (originalAddress.LatitudeDecimal != updatedAddress.LatitudeDecimal)
            {
                wizardMessages.AddMessage("Latitude will be updated to \"" + updatedAddress.LatitudeDecimal + "\".", true);
            }
            if (originalAddress.LongitudeDecimal != updatedAddress.LongitudeDecimal)
            {
                wizardMessages.AddMessage("Longitude will be updated to \"" + updatedAddress.LongitudeDecimal + "\".", true);
            }
            if (originalAddress.MappingQualityCode != updatedAddress.MappingQualityCode)
            {
                wizardMessages.AddMessage("Mapping Quality Code will be updated to \"" + updatedAddress.MappingQualityCode + "\".", true);
            }
            if (originalAddress.PostalCode != updatedAddress.PostalCode)
            {
                wizardMessages.AddMessage("PostalCode will be updated to \"" + updatedAddress.PostalCode + "\".", true);
            }
            if (originalAddress.ReplicatedFromClientMaintenanceFlag != updatedAddress.ReplicatedFromClientMaintenanceFlag)
            {
                wizardMessages.AddMessage("Replicated from ClientMaintenance Flag will be updated to \"" + updatedAddress.ReplicatedFromClientMaintenanceFlag + "\".", true);
            }
            //Not Needed - Country is also Part of Location
            //if (originalAddress.CountryCode != updatedAddress.CountryCode)
            //{
            //    wizardMessages.AddMessage("Country will be updated to \"" + updatedAddress.CountryName + "\".", true);
            //}



            /*Systemusers*/
            SystemUserRepository         systemUserRepository         = new SystemUserRepository();
            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();

            if (updatedLocationViewModel.SystemUsersAdded != null)
            {
                if (updatedLocationViewModel.SystemUsersAdded.Count > 0)
                {
                    foreach (SystemUser item in updatedLocationViewModel.SystemUsersAdded)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        if (systemUser != null)
                        {
                            wizardMessages.AddMessage("You will add User \"" + systemUser.LastName + "," + (systemUser.MiddleName != "" ? systemUser.MiddleName + " " : "") + systemUser.FirstName + "\".", true);

                            SystemUserLocation systemUserLocation = new SystemUserLocation();
                            systemUserLocation = systemUserLocationRepository.GetSystemUserLocation(item.SystemUserGuid);
                            if (systemUserLocation != null)
                            {
                                systemUserLocationRepository.EditForDisplay(systemUserLocation);
                                wizardMessages.AddMessage("The user will be moved from Location: " + systemUserLocation.LocationName + ".", true);
                            }
                        }
                    }
                }
            }
            if (updatedLocationViewModel.SystemUsersRemoved != null)
            {
                if (updatedLocationViewModel.SystemUsersRemoved.Count > 0)
                {
                    foreach (SystemUser item in updatedLocationViewModel.SystemUsersRemoved)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        if (systemUser != null)
                        {
                            wizardMessages.AddMessage("You will remove User \"" + systemUser.LastName + "," + (systemUser.MiddleName != "" ? systemUser.MiddleName + " " : "") + systemUser.FirstName + "\".", true);
                        }
                    }
                }
            }



            return(wizardMessages);
        }
コード例 #5
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
            }));
        }
コード例 #6
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
            }));
        }