public ActionResult EditFont(int id) { FontRecord record = _fontService.GetFont(id); FontViewModel editRecord = new FontViewModel() { }; editRecord.Id = record.Id; editRecord.Family = record.Family; editRecord.FileName = record.FileName; string[] stringSeparators = new string[] { ","}; string[] separatedTags; string Tags = record.Tags.Trim(new Char[] { '[', '*', ',', ']',' ', '.' }); Tags = Tags.Replace("\"",""); string resultTags = ""; separatedTags = Tags.Split(stringSeparators, StringSplitOptions.None); int i = 0; foreach (var item in separatedTags) { if (i != 0) { resultTags = resultTags + "," + " "; } resultTags = resultTags + item; i++; } editRecord.Tags = resultTags; return View(editRecord); }
public ActionResult AddFont(FontViewModel record) { if (record != null) { return View(record); } return View(); }
public RedirectToRouteResult UploadWoffFile(HttpPostedFileBase file, FontViewModel model) { if (file != null && file.ContentLength > 0) { string[] allowed = { ".woff" }; var extension = System.IO.Path.GetExtension(file.FileName); if (allowed.Contains(extension)) { string fileExt = Path.GetExtension(file.FileName); string fileName = Path.GetFileNameWithoutExtension(file.FileName).Replace("-webfont", ""); var path = Path.Combine(Server.MapPath("/Modules/Teeyoot.Module/Content/fonts/"), file.FileName); file.SaveAs(path); model.WoffFile = file.FileName; model.FileName = fileName; Services.Notifier.Information(T("WOFF file has been added!")); return RedirectToAction("AddFont", model); } } Services.Notifier.Error(T("Wrong file extention!")); return RedirectToAction("AddFont", model); }
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"); }