Ejemplo n.º 1
0
 public string ModifyPost(post post)
 {
     try
     {
         var result = _entities.posts.Find(post.id);
         result.topic = post.topic;
         result.intro = post.intro;
         result.body = post.body;
         Save();
         return "Post Modified successfully";
     }
     catch (Exception)
     {
         return "An error occured. Please retry?ERROR";
     }
 }
Ejemplo n.º 2
0
        public ActionResult MakePost(string postedBy, string intro, string topic, string body, HttpPostedFileBase picture)
        {
            if (SessionParameters.GetUserAuthenticated() &&
                request.GetUser(SessionParameters.GetCurrentUser()).userType.Trim().Equals(UserTypes.ADMIN))
            {
                try
                {
                    if (picture != null)
                    {
                        var extension = Path.GetExtension(picture.FileName);

                        var pic = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
                                           DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() +
                                           DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();

                        var path = Path.Combine(Server.MapPath("~/Content/Uploads/Photos/"), pic + extension);
                        picture.SaveAs(path);

                        var scaled = Utils.Scale(Image.FromFile(path), 261, 193);
                        System.IO.File.Delete(path);
                        scaled.Save(path);
                        var picture2 = Utils.Scale(Image.FromFile(path), 75, 75);
                        var path2 = Path.Combine(Server.MapPath("~/Content/Uploads/Photos/Small/"), pic + extension);
                        picture2.Save(path2);

                        var p = new post
                        {
                            postedBy = postedBy,
                            topic = topic,
                            intro = intro,
                            body = body,
                            image = (pic + extension),
                            postDate = DateTime.Now
                        };
                        var r = _blogger.AddPost(p);
                        if (r.Contains("ERROR"))
                        {
                            ViewBag.Status = "ERROR";
                            ViewBag.StatusMessage = r.Substring(0, r.LastIndexOf("?", StringComparison.Ordinal));
                        }
                        else
                        {
                            ViewBag.Status = "SUCCESS";
                            ViewBag.StatusMessage = r;
                        }
                        var result = _blogger.GetPosts();
                        TempData["Posts"] = result.ToList();
                        TempData.Keep("Posts");
                    }
                }
                catch (Exception)
                {
                    //Ignore
                }
                return View();
            }
            return RedirectToAction("OtherUser", "Home");
        }