示例#1
0
        public async Task <IActionResult> RequestFollow([FromBody] FollowDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ManagedErrorResponse(ManagedErrorCode.Validation, "Hay errores de validación", ModelState)));
            }
            try{
                AppUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

                if (model.UserId == currentUser.EndUserId)
                {
                    return(BadRequest(new ManagedErrorResponse(ManagedErrorCode.Validation, "Usuario no existe", new List <string>()
                    {
                        $"Un usuario no se puede seguir a sí mismo"
                    })));
                }
                if (_userRepository.FindById(model.UserId) == null)
                {
                    return(BadRequest(new ManagedErrorResponse(ManagedErrorCode.Validation, "Usuario no existe", new List <string>()
                    {
                        $"El usuario con Id {model.UserId} no existe"
                    })));
                }
                if (_userRepository.GetFollowed(currentUser.EndUserId, model.UserId) != null)
                {
                    return(BadRequest(new ManagedErrorResponse(ManagedErrorCode.Validation, "Follow existente", new List <string>()
                    {
                        $"El usuario con Id {model.UserId} ya es seguido por este usuario"
                    })));
                }
                if (_followingRequestRepository.GetFollowingRequest(currentUser.EndUserId, model.UserId) != null)
                {
                    return(BadRequest(new ManagedErrorResponse(ManagedErrorCode.Validation, "Follow Request existente", new List <string>()
                    {
                        $"Ya se le ha enviad un request al usuario con Id {model.UserId}"
                    })));
                }
                FollowingRequest followRequest = new FollowingRequest {
                    Id          = Guid.NewGuid().ToString(),
                    CreatedAt   = DateTime.Now,
                    FollowedId  = model.UserId,
                    RequesterId = currentUser.EndUserId,
                    Status      = FollowingRequestStatus.New
                };
                _followingRequestRepository.Create(followRequest);
                _endContext.SaveChanges();

                return(Ok(followRequest));
            }catch (Exception ex) {
                return(BadRequest(new ManagedErrorResponse(ManagedErrorCode.Exception, "Exception", ex)));
            }
        }
示例#2
0
        public async Task <Response <OperationResult> > Create(string userId, FollowingRequest model)
        {
            var responce = new Response <OperationResult>();

            var entity = new ComunityEntity(userId, model);

            await _context.Comunities.AddAsync(entity);

            await _context.SaveChangesAsync();

            responce.Data = OperationResult.Success;
            return(responce);
        }
示例#3
0
 public ComunityEntity(string userId, FollowingRequest model)
 {
     FollowingFromId = userId;
     FollowingToId   = model.FollowUserId;
     Status          = FollowingStatus.Pending;
 }