Ejemplo n.º 1
0
        public PostAndUserVM LogIn(PostAndUserVM user)
        {
            userLogedin = _context.Users.FirstOrDefault(x => x.Name == user.User.Name && x.Password == user.User.Password);


            if (userLogedin != null)
            {
                return(user);
            }
            throw new NotImplementedException();
        }
Ejemplo n.º 2
0
 public IActionResult LogIn1(PostAndUserVM userVM)
 {
     try
     {
         var model = _service.LogIn(userVM);
         return(View("BasePage", model /*UserService.userLogedin.User*/));
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 3
0
        public PostAndUserVM Create(UserPostVM userPost)
        {
            //user = UserService.userLogedin;
            userPost.User = UserService.userLogedin;
            try
            {
                if (userPost.User.Id == UserService.userLogedin.Id)
                {
                    if (userPost.Title != null || userPost.Description != null)
                    {
                        Post post = new Post
                        {
                            Title       = userPost.Title,
                            Description = userPost.Description,
                            CreatedAt   = DateTime.Now,
                            UserId      = userPost.User.Id,
                            CreatedBy   = userPost.User.Name,
                            Link        = userPost.Link,
                            Location    = userPost.Location,
                            Thumbnail   = userPost.Thumbnail
                        };
                        _context.Posts.Add(post);
                        //user.Posts.Append(post);
                        //user.UpdatedAt = DateTime.Now;
                        //user.UpdatedBy = "Activity App auto update";
                        //_context.Users.Update(user);
                        _context.SaveChanges();

                        /*if (post.UserId == user.Id)
                         * {
                         *  user.Posts.Append(post);
                         *  _context.Users.Update(user);
                         *  _context.SaveChanges();
                         * }*/
                        PostAndUserVM postVM = new PostAndUserVM
                        {
                            User = userPost.User,
                            Post = post
                        };
                        return(postVM);
                    }
                }
                throw new NotImplementedException();
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
 public PostsVM GetOwn(PostAndUserVM userPost)
 {
     userPost.User = UserService.userLogedin;
     try
     {
         if (userPost.User != null)
         {
             var ownPosts = new PostsVM();
             ownPosts.Posts = _context.Posts.Where(p => p.UserId == userPost.User.Id).ToList();
             return(ownPosts);
             //var vmPosts = userVM.Posts;
             //vmPosts = ownPosts;
             //return vmPosts;
         }
         throw new NotImplementedException();
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 5
0
        public void DeletePost(PostAndUserVM postAndUser)
        {
            postAndUser.User = UserService.userLogedin;

            try
            {
                //if (user.User == null || post.Post == null)
                //{
                //  throw new NotImplementedException();
                //}
                if (postAndUser.User.Id == postAndUser.Post.UserId)
                {
                    var postDel = _context.Posts.SingleOrDefault(p => p.Id == postAndUser.Post.Id);
                    _context.Posts.Remove(postDel);
                    _context.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        public DeletePostVM DeletePostPrep(PostAndUserVM postAndUser)
        {
            postAndUser.User = UserService.userLogedin;

            //try
            //{

            if (postAndUser.User != null)
            {
                var post = new DeletePostVM();
                post.Post = _context.Posts.Single(p => p.Id == postAndUser.Post.Id);
                return(post);
            }
            throw new NotImplementedException();

            //}
            //catch (Exception)
            //{

            //  throw;
            //}
        }
Ejemplo n.º 7
0
 public IActionResult DeleteFinal(PostAndUserVM postAndUser)
 {
     _service.DeletePost(postAndUser);
     return(View("MyProfile"));
 }
Ejemplo n.º 8
0
        public IActionResult Delete(PostAndUserVM postVM) //null
        {
            var model = _service.DeletePostPrep(postVM);

            return(View(model));
        }
Ejemplo n.º 9
0
        public IActionResult MyProfile(PostAndUserVM userVM)
        {
            var model = _service.GetOwn(userVM);

            return(View("MyProfile", model));
        }