Beispiel #1
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var like = await _repo.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("Tu as déja liké ce membre"));
            }
            if (await _repo.GetUser(recipientId) == null)
            {
                return(NotFound());
            }
            like = new Like
            {
                LikerId = id,
                LikeeId = recipientId
            };
            _repo.Add <Like>(like);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest(" Like échoué "));
        }
Beispiel #2
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var like = await _repo.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("لقد قمت بالإعجاب بهذا المشترك من قبل"));
            }
            if (await _repo.GetUser(recipientId) == null)
            {
                return(NotFound());
            }
            like = new Like {
                LikerId = id,
                LikeeId = recipientId
            };
            _repo.Add <Like>(like);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("فشل فى الإعجاب"));
        }
Beispiel #3
0
        public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto)
        {
            var sender = await _repo.GetUser(userId, true);

            if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            messageForCreationDto.SenderId = userId;
            var recipient = await _repo.GetUser(messageForCreationDto.RecipientId, false);

            if (recipient == null)
            {
                return(BadRequest("لم يتم الوصول للمرسل اليه"));
            }
            var message = _mapper.Map <Message>(messageForCreationDto);

            _repo.Add(message);            //in memory so we dont have to use await
            if (await _repo.SaveAll())
            {
                var messageToReturn = _mapper.Map <MessageToReturnDto>(message);
                return(CreatedAtRoute("GetMessage", new { id = message.Id }, messageToReturn));
            }

            throw new Exception("حدثت مشكلة في حفظ الرسالة الجديدة");
        }
Beispiel #4
0
        public async Task <IActionResult> AddPhotoForUser(int userId, [FromForm] PhotoForCreateDto photoForCreateDto)
        {
            var userIdFromToken = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (userIdFromToken != userId)
            {
                return(Unauthorized());
            }
            var userFromRepo = await _repo.GetUser(userId);

            var file   = photoForCreateDto.File;
            var result = UploadPhotoToCloudinary(file);

            photoForCreateDto.Url          = result.Uri.ToString();
            photoForCreateDto.CloudinaryId = result.PublicId;
            var photo = _mapper.Map <Photo>(photoForCreateDto);

            if (!userFromRepo.Photos.Any(p => p.IsMain))
            {
                photo.IsMain = true;
            }
            photo.UserId = userId;
            _repo.Add <Photo>(photo);
            if (await _repo.SaveAll())
            {
                var photoForReturn = _mapper.Map <PhotoForReturnDto>(photo);
                return(CreatedAtRoute("GetPhoto", new { id = photo.Id }, photoForReturn));
            }
            return(BadRequest(" Error in Add Photo"));
        }
Beispiel #5
0
        public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto)
        {
            var sender = await _repo.GetUser(userId);

            if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            messageForCreationDto.SenderId = userId;
            var recipient = await _repo.GetUser(messageForCreationDto.RecipientId);

            if (recipient == null)
            {
                return(BadRequest("Destinataire inexistant"));
            }
            var message = _mapper.Map <Message>(messageForCreationDto);

            _repo.Add(message);

            if (await _repo.SaveAll())
            {
                var messageToReturn = _mapper.Map <MessageToReturnDto>(message);
                return(CreatedAtRoute("GetMessage", new { id = message.Id }, messageToReturn));
            }

            throw new Exception("Un problème est survenu");
        }
Beispiel #6
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _repo.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("this user likee By this user Before"));
            }
            var userFromRepo = await _repo.GetUser(recipientId);

            if (userFromRepo == null)
            {
                return(NotFound("this user recipient is not found in data base"));
            }

            like = new Like
            {
                LikerId = id,
                LikeeId = recipientId
            };
            _repo.Add <Like>(like);
            if (await _repo.SaveAll())
            {
                return(Ok("Save user Like sccuss"));
            }
            return(BadRequest("Save user Like Error"));
        }