Esempio n. 1
0
        public static IEnumerable <FontViewModel> GetNewFonts()
        {
            List <FontViewModel> fonts = new List <FontViewModel>();

            foreach (var fontFamily in Fonts.SystemFontFamilies)
            {
                Font font = new Font();
                font.FontFamily = fontFamily;
                font.Size       = 12;
                font.IsFavorite = false;
                List <Culture> cultures = new List <Culture>();
                foreach (var family in fontFamily.FamilyNames)
                {
                    cultures.Add(new Culture {
                        CultureType = family.Key.ToString(), Name = family.Value
                    });
                }
                font.Cultures = cultures;
                font.Comment  = "";
                FontViewModel fontViewModel = new FontViewModel(font);
                fonts.Add(fontViewModel);
            }

            return(fonts);
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 public ActionResult AddFont(FontViewModel record)
 {
     if (record != null)
     {
         return(View(record));
     }
     return(View());
 }
Esempio n. 4
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"));
        }
Esempio n. 5
0
 public RedirectToRouteResult UploadThumbnail(HttpPostedFileBase file, FontViewModel model)
 {
     if (file != null && file.ContentLength > 0)
     {
         string[] allowed   = { ".png" };
         var      extension = System.IO.Path.GetExtension(file.FileName);
         if (allowed.Contains(extension))
         {
             string fileExt  = Path.GetExtension(file.FileName);
             string fileName = Path.GetFileNameWithoutExtension(file.FileName);
             var    path     = Path.Combine(Server.MapPath("/Modules/Teeyoot.Module/Content/fonts/"), file.FileName);
             file.SaveAs(path);
             model.Thumbnail = file.FileName;
             Services.Notifier.Information(T("Thumbnail has been added!"));
             return(RedirectToAction("AddFont", model));
         }
     }
     Services.Notifier.Error(T("Wrong file extention!"));
     return(RedirectToAction("AddFont", model));
 }
Esempio n. 6
0
        internal static IEnumerable <FontViewModel> GetFontsFromFile()
        {
            List <FontViewModel>    fonts      = new List <FontViewModel>();
            IEnumerable <SavedFont> savedFonts = Json.DeserializeFontsFromFile($"{AppDomain.CurrentDomain.BaseDirectory}settings.json");

            foreach (var fontFamily in Fonts.SystemFontFamilies)
            {
                Font font = new Font();
                font.FontFamily = fontFamily;
                font.Size       = 12;
                font.IsFavorite = false;
                List <Culture> cultures = new List <Culture>();

                foreach (var family in fontFamily.FamilyNames)
                {
                    cultures.Add(new Culture {
                        CultureType = family.Key.ToString(), Name = family.Value
                    });
                }

                font.Cultures = cultures;
                font.Comment  = "";

                var savedFont = savedFonts.Where(f => f.FontFamily.Equals(font.FontFamily.ToString())).FirstOrDefault();

                //save some time if no fonts were loaded from save file
                if (savedFonts.Any())
                {
                    if (savedFont != null)
                    {
                        font.IsFavorite = savedFont.IsFavorite;
                        font.Comment    = savedFont.Comment;
                    }
                }

                FontViewModel fontViewModel = new FontViewModel(font);
                fonts.Add(fontViewModel);
            }
            return(fonts);
        }
Esempio n. 7
0
        public JsonResult DetailBySeq(int font_seq)
        {
            try
            {
                var font = db.Font
                           .Where(f => !f.deleted_at.HasValue && f.seq == font_seq)
                           .FirstOrDefault();

                if (font == null)
                {
                    return(Json(new { state = "no font" }, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
                }

                var model = new FontViewModel
                {
                    created_at  = font.created_at.HasValue ? font.created_at.Value.ToString("yyyy-MM-dd") : null,
                    font_seq    = font.seq,
                    format      = font.format,
                    info        = font.info,
                    intro       = font.intro,
                    is_free     = font.is_free.HasValue ? font.is_free.Value : Free.no,
                    is_personal = font.is_personal.HasValue ? font.is_personal.Value : 1,
                    name        = font.name,
                    os          = font.os,
                    period      = font.period.HasValue ? font.period.Value : 0,
                    photos      = font.FontPhoto
                                  .Where(fp => !fp.deleted_at.HasValue)
                                  .Select(fp => fp.photo_url)
                                  .ToList(),
                    price            = font.price.HasValue ? font.price.Value : 0,
                    price_commercial = font.price_commercial.HasValue ? font.price_commercial.Value : 0,
                    seller_name      = font.seller_name,
                    file_url         = font.file_url,
                    link_url         = font.link_url,
                    click_count      = font.click_count,
                    important_point  = font.important_point,
                };

                if (font.brand_seq.HasValue)
                {
                    model.brand_info = new BrandViewModel
                    {
                        brand_seq  = font.brand_seq,
                        brand_url  = font.Brand.brand_url,
                        created_at = (font.Brand != null && font.Brand.created_at.HasValue) ? font.Brand.created_at.Value.ToString("yyyy-MM-dd") : null,
                        info       = font.Brand.info,
                        name       = font.Brand.name,
                        font_count = db.Font
                                     .Count(t => !t.deleted_at.HasValue && t.brand_seq == font.brand_seq)
                    };
                }

                var result = new
                {
                    state = "ok",
                    data  = model
                };

                return(Json(result, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
            catch (HttpException e)
            {
                Response.StatusCode = e.GetHttpCode();
                return(Json(e.Message, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
        }
 public override void UpdateFontVMCompletelyWithThisFontConfiguration(FontViewModel fontVM)
 {
     fontVM.Update(this);
 }
Esempio n. 9
0
        public JsonResult AdminList()
        {
            try
            {
                var fonts = db.Font
                            .Where(a => !a.deleted_at.HasValue)
                            .OrderByDescending(a => a.created_at)
                            .ToList();

                var data = new List <FontViewModel>();
                foreach (var f in fonts)
                {
                    var model = new FontViewModel
                    {
                        created_at  = f.created_at.HasValue ? f.created_at.Value.ToString("yyyy-MM-dd") : null,
                        font_seq    = f.seq,
                        format      = f.format,
                        info        = f.info,
                        intro       = f.intro,
                        is_free     = f.is_free.HasValue ? f.is_free.Value : Free.no,
                        is_personal = f.is_personal.HasValue ? f.is_personal.Value : 1,
                        name        = f.name,
                        os          = f.os,
                        period      = f.period.HasValue ? f.period.Value : 0,
                        photos      = f.FontPhoto
                                      .Where(fp => !fp.deleted_at.HasValue)
                                      .Select(fp => fp.photo_url)
                                      .ToList(),
                        price            = f.price.HasValue ? f.price.Value : 0,
                        price_commercial = f.price_commercial.HasValue ? f.price_commercial.Value : 0,
                        seller_name      = f.seller_name,
                        click_count      = f.click_count,
                        important_point  = f.important_point,
                        file_url         = f.file_url,
                        link_url         = f.link_url,
                    };

                    if (f.brand_seq.HasValue)
                    {
                        model.brand_info = new BrandViewModel
                        {
                            brand_seq  = f.brand_seq.HasValue ? f.brand_seq.Value : 0,
                            brand_url  = f.Brand != null ? f.Brand.brand_url : null,
                            created_at = (f.Brand != null && f.Brand.created_at.HasValue) ? f.Brand.created_at.Value.ToString("yyyy-MM-dd") : null,
                            info       = f.Brand != null ? f.Brand.info : null,
                            name       = f.Brand != null ? f.Brand.name : null,
                            font_count = db.Font
                                         .Count(t => !t.deleted_at.HasValue && t.brand_seq == f.brand_seq)
                        };
                    }
                    data.Add(model);
                }

                var result = new
                {
                    state       = "ok",
                    data        = data,
                    total_count = fonts.Count()
                };

                return(Json(result, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
            catch (HttpException e)
            {
                Response.StatusCode = e.GetHttpCode();
                return(Json(e.Message, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 10
0
        public JsonResult ListBySeq(string font_seqs)
        {
            try
            {
                var font_seqs_int = new List <int>();
                var splited       = font_seqs.Split(',');
                foreach (var item in splited)
                {
                    if (item == "" || item == null)
                    {
                        continue;
                    }
                    var item_int = Convert.ToInt32(item);
                    font_seqs_int.Add(item_int);
                }
                var query = db.Font
                            .Where(a => !a.deleted_at.HasValue);

                var fonts = query
                            .Where(q => font_seqs_int.Contains(q.seq))
                            .ToList();

                var data = new List <FontViewModel>();
                foreach (var f in fonts)
                {
                    var model = new FontViewModel
                    {
                        created_at  = f.created_at.HasValue ? f.created_at.Value.ToString("yyyy-MM-dd") : null,
                        font_seq    = f.seq,
                        format      = f.format,
                        info        = f.info,
                        intro       = f.intro,
                        is_free     = f.is_free.HasValue ? f.is_free.Value : Free.no,
                        is_personal = f.is_personal.HasValue ? f.is_personal.Value : 1,
                        name        = f.name,
                        os          = f.os,
                        period      = f.period.HasValue ? f.period.Value : 0,
                        photos      = f.FontPhoto
                                      .Where(fp => !fp.deleted_at.HasValue)
                                      .Select(fp => fp.photo_url)
                                      .ToList(),
                        price            = f.price.HasValue ? f.price.Value : 0,
                        price_commercial = f.price_commercial.HasValue ? f.price_commercial.Value :0,
                        seller_name      = f.seller_name,
                        file_url         = f.file_url,
                        link_url         = f.link_url
                    };

                    if (f.brand_seq.HasValue)
                    {
                        model.brand_info = new BrandViewModel
                        {
                            brand_seq  = f.brand_seq.HasValue ? f.brand_seq.Value : 0,
                            brand_url  = f.Brand != null ? f.Brand.brand_url : null,
                            created_at = (f.Brand != null && f.Brand.created_at.HasValue) ? f.Brand.created_at.Value.ToString("yyyy-MM-dd") : null,
                            info       = f.Brand != null ? f.Brand.info : null,
                            name       = f.Brand != null ? f.Brand.name : null,
                            font_count = db.Font
                                         .Count(t => !t.deleted_at.HasValue && t.brand_seq == f.brand_seq)
                        };
                    }
                    data.Add(model);
                }

                var result = new
                {
                    state       = "ok",
                    data        = data,
                    total_count = query.Count()
                };

                return(Json(result, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
            catch (HttpException e)
            {
                Response.StatusCode = e.GetHttpCode();
                return(Json(e.Message, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 11
0
        public JsonResult Detail(int font_seq, int flag, int use)
        {
            try
            {
                var f = db.Font
                        .Where(a => !a.deleted_at.HasValue && a.seq == font_seq)
                        .FirstOrDefault();

                if (f == null)
                {
                    throw new HttpException((int)HttpStatusCode.BadRequest, "no font");
                }

                // 선택한 폰트 이전,다음 데이터 가져오기
                var font_query = db.Font
                                 .Where(a => !a.deleted_at.HasValue);
                var prev_font = new SimpleFontViewModel();
                var next_font = new SimpleFontViewModel();

                if (flag == FontType.free)
                {
                    font_query = font_query
                                 .Where(q => q.price == 0);
                }

                if (flag == FontType.brand)
                {
                    font_query = font_query
                                 .Where(q => q.brand_seq == f.brand_seq);
                }

                if (use == FontUse.commercial)
                {
                    font_query = font_query
                                 .Where(q => q.is_personal == 0 || q.is_personal == 2);
                }

                if (use == FontUse.personal)
                {
                    font_query = font_query
                                 .Where(q => q.is_personal == 1 || q.is_personal == 2);
                }

                var prev_info = font_query
                                .Where(a => (a.important_point < f.important_point) && a.seq != f.seq)
                                .OrderByDescending(a => a.important_point)
                                .ThenByDescending(a => a.created_at)
                                .FirstOrDefault();

                if (prev_info != null)
                {
                    prev_font.created_at  = prev_info.created_at.HasValue ? prev_info.created_at.Value.ToString("yyyy-MM-dd") : null;
                    prev_font.font_seq    = prev_info.seq;
                    prev_font.name        = prev_info.name;
                    prev_font.is_personal = use;
                }

                var next_info = font_query
                                .Where(a => (a.important_point >= f.important_point) && a.seq != f.seq)
                                .OrderBy(a => a.important_point)
                                .ThenBy(a => a.created_at)
                                .FirstOrDefault();

                if (next_info != null)
                {
                    next_font.created_at  = next_info.created_at.HasValue ? next_info.created_at.Value.ToString("yyyy-MM-dd") : null;
                    next_font.font_seq    = next_info.seq;
                    next_font.name        = next_info.name;
                    next_font.is_personal = use;
                }

                f.important_point += 100;
                db.SaveChanges();

                // 폰트 정보
                var font = new FontViewModel
                {
                    created_at  = f.created_at.HasValue ? f.created_at.Value.ToString("yyyy-MM-dd"): null,
                    font_seq    = f.seq,
                    format      = f.format,
                    info        = f.info,
                    intro       = f.intro,
                    is_free     = f.is_free.HasValue ? f.is_free.Value : Free.no,
                    is_personal = f.is_personal.HasValue ? f.is_personal.Value : 1,
                    name        = f.name,
                    os          = f.os,
                    period      = f.period.HasValue ? f.period.Value : 0,
                    photos      = f.FontPhoto
                                  .Where(fp => !fp.deleted_at.HasValue)
                                  .Select(fp => fp.photo_url)
                                  .ToList(),
                    price            = f.price.HasValue ? f.price.Value : 0,
                    price_commercial = f.price_commercial.HasValue ? f.price_commercial.Value : 0,
                    //seller_name = f.Brand != null ? f.Brand.name : null,
                    file_url  = f.file_url,
                    link_url  = f.link_url,
                    prev_font = prev_font,
                    next_font = next_font
                };

                if (f.brand_seq.HasValue)
                {
                    font.brand_info = new BrandViewModel
                    {
                        brand_seq  = f.brand_seq,
                        brand_url  = f.Brand.brand_url,
                        created_at = (f.Brand != null && f.Brand.created_at.HasValue) ? f.Brand.created_at.Value.ToString("yyyy-MM-dd") : null,
                        info       = f.Brand.info,
                        name       = f.Brand.name,
                        font_count = db.Font
                                     .Count(t => !t.deleted_at.HasValue && t.brand_seq == f.brand_seq)
                    };
                }

                return(Json(font, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
            catch (HttpException e)
            {
                Response.StatusCode = e.GetHttpCode();
                return(Json(e.Message, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 12
0
        public JsonResult Fonts(int brand_seq, int page = 1)
        {
            try
            {
                var query = db.Font
                            .Where(a => !a.deleted_at.HasValue)
                            .Where(a => (a.price > 0 && a.is_personal == 1) || (a.price_commercial > 0 && a.is_personal == 0) || (a.price > 0 && a.price > 0 && a.is_personal == 2));

                if (brand_seq == 0)
                {
                    query = query
                            .Where(q => q.brand_seq.HasValue);
                }
                else
                {
                    query = query
                            .Where(q => q.brand_seq == brand_seq);

                    var brand = db.Brand
                                .Where(b => !b.deleted_at.HasValue && b.seq == brand_seq)
                                .FirstOrDefault();

                    if (brand != null)
                    {
                        brand.important_point += 100;
                        db.SaveChanges();
                    }
                }

                query = query
                        .OrderByDescending(q => q.important_point);

                var fonts = query
                            .Skip((page - 1) * 30)
                            .Take(30)
                            .ToList();

                var data = new List <FontViewModel>();
                foreach (var f in fonts)
                {
                    var model = new FontViewModel
                    {
                        created_at  = f.created_at.HasValue ? f.created_at.Value.ToString("yyyy-MM-dd") : null,
                        font_seq    = f.seq,
                        format      = f.format,
                        info        = f.info,
                        intro       = f.intro,
                        is_free     = f.is_free.HasValue ? f.is_free.Value : Free.no,
                        is_personal = f.is_personal.HasValue ? f.is_personal.Value : 1,
                        name        = f.name,
                        os          = f.os,
                        period      = f.period.HasValue ? f.period.Value : 0,
                        photos      = f.FontPhoto
                                      .Where(fp => !fp.deleted_at.HasValue)
                                      .Select(fp => fp.photo_url)
                                      .ToList(),
                        price       = f.price.HasValue ? f.price.Value : 0,
                        seller_name = f.seller_name,
                        file_url    = f.file_url,
                        link_url    = f.link_url
                    };

                    if (f.brand_seq.HasValue)
                    {
                        model.brand_info = new BrandViewModel
                        {
                            brand_seq  = f.brand_seq.HasValue ? f.brand_seq.Value : 0,
                            brand_url  = f.Brand != null ? f.Brand.brand_url : null,
                            created_at = (f.Brand != null && f.Brand.created_at.HasValue) ? f.Brand.created_at.Value.ToString("yyyy-MM-dd") : null,
                            info       = f.Brand != null ? f.Brand.info : null,
                            name       = f.Brand != null ? f.Brand.name : null,
                            font_count = db.Font
                                         .Count(t => !t.deleted_at.HasValue && t.brand_seq == f.brand_seq)
                        };
                    }
                    data.Add(model);
                }

                var result = new
                {
                    state       = "ok",
                    data        = data,
                    total_count = query.Count()
                };

                return(Json(result, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
            catch (HttpException e)
            {
                Response.StatusCode = e.GetHttpCode();
                return(Json(e.Message, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 13
0
 public abstract void UpdateFontVMCompletelyWithThisFontConfiguration(FontViewModel fontVM);