Exemplo n.º 1
0
        public ActionResult SetMainPhoto(int announcementId, int photoId)
        {
            bool         res          = false;
            Announcement announcement = _announcementRepository.GetById(announcementId);

            User authenticatedUser = _userRepository.GetUserByPhone(User.Identity.Name);

            if (authenticatedUser == announcement.User)
            {
                foreach (Photo photo in announcement.Photos)
                {
                    if (photo.PhotoId == photoId)
                    {
                        photo.IsMain = true;
                    }
                    else
                    {
                        photo.IsMain = false;
                    }
                }
                _photoRepository.SaveChanges();
                res = true;
            }

            return(Json(new { Done = res }, "text/json"));
        }