Beispiel #1
0
        public ActionResult Create(Blog.Entry model,HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                model.CreatedDate = DateTime.UtcNow;
                model.ModifyDate = DateTime.UtcNow;

                //if user not selected a photo , we'll using default photo
                //sorry for spike boys
                if (photo != null)
                {
                    var pict = new Photo
                    {
                        SourceUrl = ImageCreator.SavePhoto(photo)
                    };
                    DataAccessLayer.Create(pict);
                    DataAccessLayer.Refresh(pict);

                    model.Image = pict.SourceUrl;
                }
                else
                {
                    model.Image = "~/Content/img/del-1.png";
                }

                var binder = new BlogToBlogPost(DataAccessLayer);
                var entry = new BlogPost();
                binder.Load(model, entry);
                DataAccessLayer.Create<BlogPost>(entry);
                DataAccessLayer.DbContext.SaveChanges();
                return RedirectToAction("Posts");
            }
            return View();
        }
Beispiel #2
0
 public ActionResult Create(Blog.Entry model)
 {
     if (ModelState.IsValid)
     {
         model.CreatedDate = DateTime.Now;
         var binder = new CreateBlogToBlogPost();
         var entry = new BlogPost();
         binder.Load(model, entry);
         DataAccessLayer.Create<BlogPost>(entry);
         DataAccessLayer.DbContext.SaveChanges();
         return RedirectToAction("./Posts");
     }
     return View(model);
 }
Beispiel #3
0
        public ActionResult TopPosts()
        {
            //var listOfPosts = DataAccessLayer.TopRandom<BlogPost>(BlogsCount);
            var listOfPosts = DataAccessLayer.Get<BlogPost>().Take(BlogsCount);
            if (listOfPosts == null)
            {
                return HttpNotFound("Posts not found");
            }

            var blog = new Blog {Posts = new List<Blog.Entry>()};

            foreach (var blogPost in listOfPosts)
            {
                var binder = new BlogToBlogPost(DataAccessLayer);
                var entry = new Blog.Entry();
                binder.InverseLoad(blogPost, entry);
                blog.Posts.Add(entry);
            }

            return PartialView(blog);
        }
Beispiel #4
0
 public ActionResult Edit(Blog.Entry model)
 {
     if (ModelState.IsValid)
     {
         DataAccessLayer.UpdateById<BlogPost>(model.Id, x =>
             {
                 x.Title = model.Title;
                 x.FullText = model.FullText;
                 x.ModifyDate = DateTime.UtcNow;
             });
         DataAccessLayer.DbContext.SaveChanges();
         return Detail(model.Id);
     }
     return View();
 }