예제 #1
0
        public RedirectToRouteResult AddNewFont(FontViewModel model)
        {
            string errorMsg = "";

            if (model.Family == null)
            {
                errorMsg += T("Font family is required.\n");
            }
            if (!((model.TtfFile == null) || (model.WoffFile == null)))
            {
                errorMsg += T("Font file is required.\n");
            }
            if (model.Thumbnail == null)
            {
                errorMsg += T("Thumbnail is required.\n");
            }
            if (errorMsg.Length > 0)
            {
                Services.Notifier.Error(T(errorMsg));
                return(RedirectToAction("AddFont", model));
            }
            FontRecord newFont = new FontRecord()
            {
            };

            newFont.Family      = model.Family;
            newFont.FileName    = model.FileName;
            newFont.Priority    = 0;
            newFont.FontCulture = cultureUsed;
            int i = 0;

            if (model.Tags != null)
            {
                string[] stringSeparators = new string[] { "," };
                string[] separatedTags;
                string   resultTags = "[";
                separatedTags = model.Tags.Split(stringSeparators, StringSplitOptions.None);
                foreach (var item in separatedTags)
                {
                    if (i != 0)
                    {
                        resultTags = resultTags + ",";
                    }
                    resultTags = resultTags + "\"" + item + "\"";
                    i++;
                }
                resultTags  += "]";
                newFont.Tags = resultTags;
            }
            _fontService.AddFont(newFont);
            Services.Notifier.Information(T("The font has been added"));
            return(RedirectToAction("FontList"));
        }