Esempio n. 1
0
      public ActionResult Create(Post post, HttpPostedFileBase fileUpload)       // these are the pieces on the form (Create page)
      {
         post.Created = new DateTimeOffset(DateTime.Now);
         if (ModelState.IsValid)
         {
            // restrictin the valid file formats to images only
            if (ImageUploadValidator.IsWebFriendlyImage(fileUpload))
            {
               var fileName = Path.GetFileName(fileUpload.FileName);
               fileUpload.SaveAs(Path.Combine(Server.MapPath("~/img/"), fileName));
               post.MediaURL = "~/img/" + fileName;
            }
            post.Created = new DateTimeOffset(DateTime.Now);         // sets current system time
            db.Posts.Add(post);               // queued up in memory
            db.SaveChanges();                 // changes saved
            return RedirectToAction("Index");
         }

         return View(post);
      }
Esempio n. 2
0
        public ActionResult Edit(Post post, HttpPostedFileBase fileUpload)
        {

            //post.UpdateDate = new DateTimeOffset(DateTime.Now);
            DateTime timeUtc = DateTime.UtcNow;
            TimeZoneInfo kstZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
            DateTime kstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, kstZone);

            post.UpdateDate = kstTime;


            if (ModelState.IsValid)
            {
                var fetched = db.Posts.Find(post.Id);
                fetched.Title = post.Title;
                fetched.BodyText = post.BodyText;
                fetched.MediaUrl = post.MediaUrl;
                fetched.Published = post.Published;
                fetched.UpdateDate = post.UpdateDate;

                // restricting the valid file formats to images only
                if (Post.ImageUploadValidator.IsWebFriendlyImage(fileUpload))
                {
                    var fileName = Path.GetFileName(fileUpload.FileName);
                    fileUpload.SaveAs(Path.Combine(Server.MapPath("~/img/"), fileName));
                    fetched.MediaUrl = "~/img/" + fileName;

                }

                //post.UpdateDate = new DateTimeOffset(DateTime.Now);
                post.UpdateDate = kstTime;
                db.Entry(fetched).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            

            return View(post);
        }
Esempio n. 3
0
 public ActionResult Edit(Post post, HttpPostedFileBase fileUpload)
 {
    if (ModelState.IsValid)
    {
       // restrictin the valid file formats to images only
       if (ImageUploadValidator.IsWebFriendlyImage(fileUpload))
       {
          var fileName = Path.GetFileName(fileUpload.FileName);
          fileUpload.SaveAs(Path.Combine(Server.MapPath("~/img/"), fileName));
          post.MediaURL = "~/img/" + fileName;
       }
       post.Updated = new DateTimeOffset(DateTime.Now);
       db.Entry(post).State = EntityState.Modified;
       db.SaveChanges();
       return RedirectToAction("Details", new { id = post.Id });
    }
    return View(post);
 }
Esempio n. 4
0
        public ActionResult Create( Post post, HttpPostedFileBase fileUpload) 
        {
            //post.CreationDate = new DateTimeOffset(DateTime.Now);

            DateTime timeUtc = DateTime.UtcNow;
            TimeZoneInfo kstZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
            DateTime kstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, kstZone);

            post.CreationDate = kstTime;

            if (ModelState.IsValid)
            {
                // restricting the valid file formats to images only
                if (Post.ImageUploadValidator.IsWebFriendlyImage(fileUpload))
                {
                    var fileName = Path.GetFileName(fileUpload.FileName);
                    fileUpload.SaveAs(Path.Combine(Server.MapPath("~/img/"), fileName));
                    post.MediaUrl = "~/img/" + fileName;

                }

                //post.CreationDate = new DateTimeOffset(DateTime.Now);
                post.CreationDate = kstTime;

                db.Posts.Add(post); //add the object
                db.SaveChanges(); //creates a sql statement and sends it out
                return RedirectToAction("Index");
            }

            return View(post);
        }