Post entity. Store the data of an article
Beispiel #1
0
 public static Subscription CreateSubscription(string name, string email, bool isconfirmed, Post post)
 {
     var subscription = new Subscription();
     subscription.SubscriberName = name;
     subscription.SubscriberEmail = email;
     subscription.IsConfirmed = isconfirmed;
     subscription.ConfirmationToken = GenerateToken();
     subscription.DateCreated = DateTime.UtcNow;
     subscription.SubscriptionType = SubscriptionType.Comments;
     subscription.AddPost(post);
     return subscription;
 }
Beispiel #2
0
 public ActionResult Edit(Post post, int[] selectedtags)
 {
     Post posttoupdate = PostServices.FindAllEntities(p => p.PostId == post.PostId, null, "Tags").FirstOrDefault();
     if (TryUpdateModel(posttoupdate, "", null, new string[] { }))
     {
         try
         {
             UpdateModel(posttoupdate, "", null, new string[] { });
             BlogServices.UpdatePost(posttoupdate, selectedtags);
             return RedirectToAction("Index");
         }
         catch (DataException)
         {
             ModelState.AddModelError("", Resources.AppMessages.Error_Saving_Changes);
         }
         catch (ApplicationValidationErrorsException ex)
         {
             foreach (string str in ex.ValidationErrors)
             {
                 ModelState.AddModelError("", str);
             }
         }
     }
     ViewBag.ImageId = new SelectList(ImageServices.FindAllEntities(null, null, null), "ImageId", "FileName", post.ImageId);
     ViewBag.CategoryId = new SelectList(CategoryServices.FindAllEntities(null, null, null), "CategoryId", "Name", post.CategoryId);
     ViewBag.UserId = new SelectList(UserServices.FindAllEntities(null, null, null), "UserId", "Username", post.UserId);
     ViewBag.Tags = TagServices.FindAllEntities(null, o => o.OrderBy(t => t.TagName), null).ToDictionary<Tag, int, string>(t => t.TagId, t => t.TagName);
     return View(posttoupdate);
 }
Beispiel #3
0
 public ActionResult Create(Post post, int[] selectedtags)
 {
     if (ModelState.IsValid)
     {
         try
         {
             BlogServices.CreatePost(post, selectedtags);
             return RedirectToAction("Index");
         }
         catch (ApplicationValidationErrorsException ex)
         {
             foreach (string str in ex.ValidationErrors)
             {
                 ModelState.AddModelError("", str);
             }
         }
     }
     ViewBag.ImageId = new SelectList(ImageServices.FindAllEntities(null, null, null), "ImageId", "FileName", post.ImageId);
     ViewBag.CategoryId = new SelectList(CategoryServices.FindAllEntities(null, null, null), "CategoryId", "Name", post.CategoryId);
     ViewBag.UserId = new SelectList(UserServices.FindAllEntities(null, null, null), "UserId", "Username", post.UserId);
     ViewBag.Tags = TagServices.FindAllEntities(null, o => o.OrderBy(t => t.TagName), null).ToDictionary<Tag, int, string>(t => t.TagId, t => t.TagName);
     return View(post);
 }
Beispiel #4
0
 /// <summary>
 /// Remove a Post from the Post Collection
 /// </summary>
 /// <param name="post"></param>
 public void DeletePost(Post post)
 {
     this.Posts.Remove(post);
 }
Beispiel #5
0
 /// <summary>
 /// Add a Post to the Posts Collection
 /// </summary>
 /// <param name="post"></param>
 public void AddPost(Post post)
 {
     this.Posts.Add(post);
 }