Exemplo n.º 1
0
        private void SaveWebPost(string fileName, PostModel model)
        {
            WebPostModel wPost = new WebPostModel()
            {
                PTitle = model.PTitle,
                PText = model.PText,
                PLink = model.PLink,
                PImage = model.PImage,
                PDate = model.PDate.ToString("yyyy-MM-ddTHH:mm:ss"),
                PPrice = model.PPrice
            };

            System.IO.MemoryStream msPost = new System.IO.MemoryStream();
            System.Runtime.Serialization.Json.DataContractJsonSerializer dcJsonPost =
                new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(WebPostModel));
            dcJsonPost.WriteObject(msPost, wPost);

            using (System.IO.FileStream f2 = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
            {
                byte[] jsonArray = msPost.ToArray();

                using (System.IO.Compression.GZipStream gz =
                    new System.IO.Compression.GZipStream(f2, System.IO.Compression.CompressionMode.Compress))
                {
                    gz.Write(jsonArray, 0, jsonArray.Length);
                }
            }
        }
Exemplo n.º 2
0
        // GET: Api/Post/Add3
        public JsonResult Add3()
        {
            PostModel model = new PostModel();
            model.PDate = DateTime.Now;

            string fileName = Server.MapPath("~/App_Data/test3.json");
            model.PText = fileName;

            System.Runtime.Serialization.Json.DataContractJsonSerializer ser =
                new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(PostModel));

            System.IO.MemoryStream stream1 = new System.IO.MemoryStream();

            ser.WriteObject(stream1, model);

            using (System.IO.FileStream f2 = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
            {
                byte[] jsonArray = stream1.ToArray();

                using (System.IO.Compression.GZipStream gz =
                    new System.IO.Compression.GZipStream(f2, System.IO.Compression.CompressionMode.Compress))
                {
                    gz.Write(jsonArray, 0, jsonArray.Length);
                }
            }

            return Json(model, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 3
0
        public void Edit(PostModel model)
        {
            string commandText =
            @"UPDATE post
             SET post_link = " + SQLString(model.PLink) + @"
               , post_image = " + SQLString(model.PImage) + @"
               , post_title = " + SQLString(model.PTitle) + @"
               , post_text = " + SQLString(model.PText) + @"
               , post_price = " + SQLDecimal(model.PPrice) + @"
               , post_date = " + SQLDateTime(model.PDate) + @"
               , post_price_type_id = " + SQLInt(model.PPriceTypeId) + @"
             WHERE id = " + SQLInt(model.PostId);

            base.ExecuteNonQuery(commandText);
        }
Exemplo n.º 4
0
 public PostModel GetPost(int id)
 {
     string commandText =
     @"SELECT p.id
        , p.n_site_id
        , p.n_category_id
        , p.post_link
        , p.post_image
        , p.post_title
        , p.post_text
        , p.new_post_id
        , p.new_post_transaction_id
        , p.post_price
        , p.n_template_location_id
        , p.post_date
        , p.n_site_posted_id
        , p.post_price_type_id
      FROM post p
      WHERE p.id = " + SQLInt(id);
     PostModel model = null;
     using (DataTable dTable = base.FillDataTable(commandText))
     {
         if( dTable.Rows.Count > 0)
         {
             DataRow dRow = dTable.Rows[0];
             model = new PostModel()
             {
                 PostId = TryParse.ToInt32(dRow["id"]),
                 SiteId = TryParse.ToInt32(dRow["n_site_id"]),
                 CategoryId = TryParse.ToInt32(dRow["n_category_id"]),
                 PLink = TryParse.ToString(dRow["post_link"]),
                 PImage = TryParse.ToString(dRow["post_image"]),
                 PTitle = TryParse.ToString(dRow["post_title"]),
                 PText = TryParse.ToString(dRow["post_text"]),
                 PPrice = TryParse.ToDecimal(dRow["post_price"]),
                 TemplateLocationId = TryParse.ToInt32(dRow["n_template_location_id"]),
                 PDate = TryParse.ToDateTime(dRow["post_date"]),
                 SitePostedId = TryParse.ToInt32(dRow["n_site_posted_id"]),
                 PPriceTypeId = TryParse.ToInt32(dRow["post_price_type_id"])
             };
         }
     }
     return model;
 }
Exemplo n.º 5
0
 public ActionResult Edit(PostModel model, string redirectUrl = "")
 {
     if (!ModelState.IsValid)
     {
         using (Contexts.PostContext context = new Contexts.PostContext())
         {
             ViewBag.PostPriceTypes = context.GetPostPriceTypes(true);
         }
         return View("Edit", model);
     }
     else
     {
         using (Contexts.PostContext context = new Contexts.PostContext())
         {
             context.Edit(model);
         }
         return Redirect(redirectUrl);
     }
 }