private void AddImportedData(ImportedFormatModel importedFormat)
        {
            try
            {
                formatService.Add(importedFormat.ImportedFormat);

                foreach (StyleClass styleClass in importedFormat.ImportedStyleClasses)
                {
                    try
                    {
                        styleClassService.Add(styleClass);
                    }
                    catch (ExistingStyleClassException exception)
                    {
                        MessageBox.Show(exception.Message);
                    }
                }

                foreach (Style style in importedFormat.ImportedStyles)
                {
                    try
                    {
                        styleService.Add(style.Format.Name, style.StyleClass.Name, style);
                    }
                    catch (InvalidStyleException exception)
                    {
                        MessageBox.Show(exception.Message);
                    }
                }
            }
            catch (ExistingFormatException exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
예제 #2
0
        private void btnSubmitStyle_Click(object sender, EventArgs e)
        {
            Style newStyle = new Style()
            {
                Key   = tbxKey.Text,
                Value = tbxValue.Text
            };

            try
            {
                styleManager.Add(selectedFormatName, selectedClassName, newStyle);
                MessageBox.Show("The style was added successfully");
                this.Close();
            } catch (InvalidStyleException exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        public IHttpActionResult AddAStyle([FromBody] AddStyle style)
        {
            if (IsTokenValid() && authenticationService.IsAllowedToAddStyles(GetTokenUserEmail()))
            {
                try
                {
                    string formatName     = Request.Headers.GetValues("Format-Name").FirstOrDefault();
                    string styleclassName = Request.Headers.GetValues("StyleClass-Name").FirstOrDefault();

                    Style     newStyle      = styleManagementService.Add(formatName, styleclassName, AddStyle.ToEntity(style));
                    BaseStyle modelNewStyle = BaseStyle.ToModel(newStyle);

                    return(CreatedAtRoute("AddStyle", new { styleid = modelNewStyle.Id }, modelNewStyle));
                }
                catch (Exceptions e)
                {
                    return(BadRequest(e.Message));
                }
            }

            return(Unauthorized());
        }