예제 #1
0
        public async Task <IActionResult> SetMainPhoto(int userid, int id)
        {
            if (userid != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhotos(id);

            if (photoFromRepo == null)
            {
                return(NotFound());
            }

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("This foto alredy is Main"));
            }

            var curentMainPhoto = await _repo.GetMainPhotoForUser(userid);

            if (curentMainPhoto != null)
            {
                curentMainPhoto.IsMain = false;
            }

            photoFromRepo.IsMain = true;

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("ble ble ble"));
        }