Beispiel #1
0
        public void SavePost(ListInformalBlogViewModel list)
        {
            try
            {
                var helper = new UserRepository();
                var images = new List <ImageModel>();
                foreach (var item in list.files)
                {
                    if (item == null)
                    {
                        continue;
                    }

                    var img = new ImageModel
                    {
                        Path = helper.SaveImage(item)
                    };
                    images.Add(img);
                }
                var model = new InformalBlogModel
                {
                    Message   = list.Message,
                    Title     = list.Title,
                    Timestamp = DateTime.Now,
                    Id        = list.SenderId,
                    Images    = images
                };
                _db.InformalBlogPosts.Add(model);
                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception();
            }
        }
        public ActionResult DeleteInformalEntry(int EntryId, string CreatorId)
        {
            InformalBlogModel blogEntry = Ctx.InformalBlogEntries.Find(EntryId);

            var currentUser   = UserManager.FindById(User.Identity.GetUserId());
            var currentUserId = currentUser.Id;

            // currentUserId.Equals(CreatorId)
            Ctx.InformalBlogEntries.Remove(blogEntry);
            Ctx.SaveChanges();

            return(RedirectToAction("Index", "InformalBlog"));
        }