Ejemplo n.º 1
0
        public async Task <UserDTO> SetProfilePicture(int photoId, int id)
        {
            var user = await _context
                       .Users
                       .Where(
                u => u.Id == id &&
                !u.IsDeleted)
                       .FirstOrDefaultAsync();

            if (user == null)
            {
                throw new Exception(USER_NULL);
            }

            Photo profilePicture = user.Photos.Where
                                   (
                p => p.Id == photoId &&
                !p.IsDeleted
                                   )
                                   .FirstOrDefault();

            if (profilePicture == null)
            {
                throw new Exception(PHOTO_NULL);
            }

            profilePicture.IsProfilePicture = true;

            await _context.SaveChangesAsync();

            return(user.GetDTO());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("UserName,FirstName,LastName,Age,Nationality,CreatedOn,EditedOn,IsDeleted,Id,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Ejemplo n.º 3
0
        public async Task <FriendDTO> AddFriend(FriendDTO friendDTO)
        {
            if (_context.Friends.Any(b => b.Id == friendDTO.Id))
            {
                throw new Exception(USER_ALREADY_IN_FRIENDLIST);
            }

            _context.Friends.Add(friendDTO.GetFriend());

            await _context.SaveChangesAsync();

            return(friendDTO);
        }
Ejemplo n.º 4
0
        public async Task <PhotoDTO> AddPhoto(PhotoDTO photoDTO)
        {
            if (_context.Photos.Any(b => b.Id == photoDTO.Id))
            {
                var oldPhoto = _context.Photos.Where(b => b.Id == photoDTO.Id).FirstOrDefault();
                _context.Photos.Remove(oldPhoto);
            }

            _context.Photos.Add(photoDTO.GetPhoto());

            await _context.SaveChangesAsync();

            return(photoDTO);
        }
Ejemplo n.º 5
0
 public async Task <FriendRequestDTO> Accept(int senderId, int receiverId)
 {
     if (await this.Exists(senderId, receiverId))
     {
         var friendRequest = _context.FriendRequests
                             .FirstOrDefault(fr => fr.ReceiverId == receiverId && fr.SenderId == senderId);
         friendRequest.FriendRequestStatus = FriendRequestStatus.Accepted;
         var friend = new Friend
         {
             userId   = senderId,
             FriendId = receiverId
         };
         _context.Friends.Add(friend);
         friendRequest.IsDeleted = true;
         await _context.SaveChangesAsync();
     }
     throw new Exception(GENERAL_ERROR);
 }
Ejemplo n.º 6
0
        public async Task <PostDTO> Create(PostDTO postDTO)
        {
            if (postDTO == null)
            {
                throw new Exception(PostNull);
            }

            var post = new Post
            {
                Content    = postDTO.Content,
                UserId     = postDTO.UserId,
                CreatedOn  = DateTime.UtcNow,
                Visability = postDTO.Visability
            };

            _context.Posts.Add(post);
            await _context.SaveChangesAsync();

            return(post.GetDTO());
        }
Ejemplo n.º 7
0
        public async Task <CommentDTO> CreateComment(CommentDTO commentDTO)
        {
            if (commentDTO.Content == null)
            {
                throw new Exception(COMMENT_NULL);
            }
            else if (commentDTO.Content.Length >= 4000)
            {
                throw new Exception(COMMENT_TOO_LONG);
            }

            var comment = new Comment
            {
                Content = commentDTO.Content,
                UserId  = commentDTO.UserId,
                PostId  = commentDTO.PostId
            };

            await _context.Comments.AddAsync(comment);

            await _context.SaveChangesAsync();

            return(comment.GetDTO());
        }