Esempio n. 1
0
        public JsonResult Edit(int font_seq, string name, int?brand_seq, List <string> photos, int is_personal, int price, int?price_commercial, string os, string format, int period, string seller_name, string file_url, string info, string intro, string link_url, int important_point)
        {
            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));
                }

                font.name      = name;
                font.brand_seq = brand_seq;
                //if (price == 0)
                //{
                //    font.is_free = 1;
                //}
                //else
                //{
                //    font.is_free = 0;
                //}
                font.is_personal     = is_personal;
                font.link_url        = link_url;
                font.file_url        = file_url;
                font.format          = format;
                font.important_point = important_point;
                font.info            = info;
                font.intro           = intro;
                font.os               = os;
                font.name             = name;
                font.period           = period;
                font.price            = price;
                font.price_commercial = price_commercial;
                font.seller_name      = seller_name;
                font.updated_at       = DateTime.Now;

                if (photos != null)
                {
                    if (photos.Count > 0)
                    {
                        var origin_photos = db.FontPhoto
                                            .Where(f => !f.deleted_at.HasValue && f.font_seq == font_seq);

                        foreach (var photo in origin_photos)
                        {
                            photo.deleted_at = DateTime.Now;
                        }

                        foreach (var photo in photos)
                        {
                            var model = new FontPhoto
                            {
                                created_at = DateTime.Now,
                                font_seq   = font_seq,
                                photo_url  = photo,
                                updated_at = DateTime.Now
                            };
                            db.FontPhoto.Add(model);
                        }
                    }
                }
                else
                {
                    var origin_photos = db.FontPhoto
                                        .Where(f => !f.deleted_at.HasValue && f.font_seq == font_seq);

                    foreach (var photo in origin_photos)
                    {
                        photo.deleted_at = DateTime.Now;
                    }
                }

                db.SaveChanges();

                var result = new
                {
                    state = "ok"
                };

                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. 2
0
        public JsonResult Add(string name, int?brand_seq, List <string> photos, int is_personal, int price, int?price_commercial, string os, string format, int period, string seller_name, string file_url, string info, string intro, string link_url, int important_point)
        {
            try
            {
                var new_font = new Font
                {
                    brand_seq       = brand_seq,
                    click_count     = 0,
                    created_at      = DateTime.Now,
                    file_url        = file_url,
                    format          = format,
                    important_point = important_point,
                    info            = info,
                    intro           = intro,
                    is_personal     = is_personal,
                    link_url        = link_url,
                    name            = name,
                    os               = os,
                    period           = period,
                    price            = price,
                    price_commercial = price_commercial,
                    seller_name      = seller_name,
                    updated_at       = DateTime.Now
                };
                //if (price == 0)
                //{
                //    new_font.is_free = 1;
                //}
                //else
                //{
                //    new_font.is_free = 0;
                //}

                db.Font.Add(new_font);
                db.SaveChanges();

                if (photos != null)
                {
                    if (photos.Count > 0)
                    {
                        foreach (var photo in photos)
                        {
                            var model = new FontPhoto
                            {
                                created_at = DateTime.Now,
                                font_seq   = new_font.seq,
                                photo_url  = photo,
                                updated_at = DateTime.Now
                            };
                            db.FontPhoto.Add(model);
                        }
                    }
                }

                db.SaveChanges();

                var result = new
                {
                    state = "ok"
                };

                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));
            }
        }