Beispiel #1
0
        public async Task <IActionResult> SetMainPhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var user = await _dating.GetUser(userId);

            if (!user.Photos.Any(u => u.Id == id))
            {
                return(Unauthorized());
            }
            var PhotoFromRepo = await _dating.GetPhoto(id);

            if (PhotoFromRepo.IsMain)
            {
                return(BadRequest("this is already main photo"));
            }

            var CurrentMainPhoto = await _dating.GetUserCurrentPhoto(userId);

            CurrentMainPhoto.IsMain = false;
            PhotoFromRepo.IsMain    = true;
            if (await _dating.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("Could not set photo to main"));
        }