public double SetRaiting(int idPhoto, string login, int rating)
        {
            User user = unitOfWork.Users.GetByLogin(login);
            Photo photo = unitOfWork.Photos.GetById(idPhoto);

            Rating r = new Rating { User = user, Value = rating, Photo = photo };
            unitOfWork.Rating.UpdateOrAdd(r, photo);
            unitOfWork.Save();

            return unitOfWork.Rating.GetRating(photo);
        }
 public void UpdateOrAdd(Rating rating, Photo photo)
 {
     Rating r = photo.Raitings.FirstOrDefault(rt=>rt.User == rating.User);
     if (r != null)
     {
         r.Value = rating.Value;
         db.Entry(r).State = EntityState.Modified;
     }
     else
         photo.Raitings.Add(rating);
 }