Esempio n. 1
0
        public Form GetForm(string context)
        {
            // Check permissions
            _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

            // Get page and element identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[0]);
            long     elementId = Convert.ToInt64(parts[1]);

            // Get current map settings
            Guid elementTypeId = FormId;
            IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId);
            MapSettings             mapSettings    = (MapSettings)elementService.New(_authenticationService.TenantId);

            mapSettings.ElementId = elementId;
            elementService.Read(mapSettings);

            // Construct form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context
            };

            form.Fields.Add("displayName", new TextField
            {
                Name                  = "displayName",
                Label                 = ElementResource.MapDisplayNameLabel,
                MaxLength             = MapLengths.DisplayNameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.MapDisplayNameMaxLengthMessage, "displayName", MapLengths.DisplayNameMaxLength),
                Value                 = mapSettings.DisplayName
            });
            form.Fields.Add("latitude", new TextField
            { // TODO: Implement this using numeric form field that accepts decimals
                Name                  = "latitude",
                Label                 = ElementResource.MapLatitudeLabel,
                MaxLength             = MapLengths.LatitudeMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.MapLatitudeMaxLengthMessage, "latitude", MapLengths.LatitudeMaxLength),
                Value                 = mapSettings.Latitude.ToString(),
                Required              = true,
                RequiredErrorMessage  = ElementResource.MapLatitudeRequiredMessage
            });
            form.Fields.Add("longitude", new TextField
            { // TODO: Implement this using numeric form field that accepts decimals
                Name                  = "longitude",
                Label                 = ElementResource.MapLongitudeLabel,
                MaxLength             = MapLengths.LongitudeMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.MapLongitudeMaxLengthMessage, "longitude", MapLengths.LongitudeMaxLength),
                Value                 = mapSettings.Longitude.ToString(),
                Required              = true,
                RequiredErrorMessage  = ElementResource.MapLongitudeRequiredMessage
            });
            form.SubmitLabel = ElementResource.MapButtonLabel;

            // Return result
            return(form);
        }
Esempio n. 2
0
        public FormResult PostForm(Form form)
        {
            try
            {
                // Check permissions
                _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

                // Get page and element identifiers
                string[] parts     = form.Context.Split('|');
                long     pageId    = Convert.ToInt64(parts[0]);
                long     elementId = Convert.ToInt64(parts[1]);

                // Get the HTML element service
                IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(FormId);

                // Get updated map settings
                MapSettings mapSettings = (MapSettings)elementService.New(_authenticationService.TenantId);
                mapSettings.ElementId   = elementId;
                mapSettings.DisplayName = string.IsNullOrWhiteSpace(((TextField)form.Fields["displayName"]).Value) ? null : ((TextField)form.Fields["displayName"]).Value;

                // Get longitude and latitude
                double latitude;
                double longitude;
                string latitudeText     = ((TextField)form.Fields["latitude"]).Value;
                string longitudeText    = ((TextField)form.Fields["longitude"]).Value;
                bool   latitudeSuccess  = Double.TryParse(latitudeText, out latitude);
                bool   longitudeSuccess = Double.TryParse(longitudeText, out longitude);
                if (!latitudeSuccess)
                {
                    throw new ValidationErrorException(new ValidationError("latitude", ElementResource.MapLatitudeInvalidMessage));
                }
                if (!longitudeSuccess)
                {
                    throw new ValidationErrorException(new ValidationError("longitude", ElementResource.MapLongitudeInvalidMessage));
                }
                mapSettings.Latitude  = latitude;
                mapSettings.Longitude = longitude;

                // Perform the update
                elementService.Update(mapSettings);

                // Return form result with no errors
                return(_formHelperService.GetFormResult());
            }
            catch (ValidationErrorException ex)
            {
                // Return form result containing errors
                return(_formHelperService.GetFormResultWithValidationErrors(ex.Errors));
            }
            catch (Exception)
            {
                // Return form result containing unexpected error message
                return(_formHelperService.GetFormResultWithErrorMessage(ApplicationResource.UnexpectedErrorMessage));
            }
        }
Esempio n. 3
0
        public void Update(MapSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                string sql = _sqlManager.GetSql("Sql.UpdateMap.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.AddParameter("@DisplayName", FieldType.NVarChar, 256, settings.DisplayName ?? (object)DBNull.Value);
                dbm.AddParameter("@Latitude", FieldType.Float, 53, settings.Latitude);
                dbm.AddParameter("@Longitude", FieldType.Float, 53, settings.Longitude);
                dbm.ExecuteNonQuery();
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Esempio n. 4
0
        public void Read(MapSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                string sql = _sqlManager.GetSql("Sql.ReadMap.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.ExecuteReader();
                dbm.Read();
                settings.DisplayName = dbm.DataReaderValue("DisplayName") == DBNull.Value ? null : (string)dbm.DataReaderValue("DisplayName");
                settings.Latitude    = (double)dbm.DataReaderValue("Latitude");
                settings.Longitude   = (double)dbm.DataReaderValue("Longitude");
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }