Ejemplo n.º 1
0
        public async Task <IActionResult> SetMainPhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var userFromRepo = await _repo.GetUser(userId, true);

            if (!userFromRepo.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }
            var DesiredMainPhoto = await _repo.GetPhoto(id);

            if (DesiredMainPhoto.IsMain)
            {
                return(BadRequest("هذه هي الصورة الأساسية بالفعل"));
            }
            var CurrentMainPhoto = await _repo.GetMainPhotoForUser(userId);

            CurrentMainPhoto.IsMain = false;
            DesiredMainPhoto.IsMain = true;
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("لايمكن تعديل الصورة الأساسية"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SetMainPhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var userFromRepo = await _repo.GetUser(userId);

            if (!userFromRepo.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }
            var DesiredMainPhoto = await _repo.GetPhoto(id);

            if (DesiredMainPhoto.IsMain)
            {
                return(BadRequest("C'est ta photo principale"));
            }
            var CurrentMainPhoto = await _repo.GetMainPhotoForUser(userId);

            CurrentMainPhoto.IsMain = false;
            DesiredMainPhoto.IsMain = true;
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("Ce n'est pas possible de modifier la photo actuel"));
        }