/// <summary>
 /// Method ToBllVoting convert DalVoting to VotingEntity.
 /// </summary>
 /// <param name="dalVoting">DalVoting that need convert.</param>
 /// <returns>VotingEntity entity.</returns>
 public static VotingEntity ToBllVoting(this DalVoting dalVoting)
 {
     return(new VotingEntity()
     {
         UserId = dalVoting.UserId,
         PhotoId = dalVoting.PhotoId,
         Rating = dalVoting.Rating
     });
 }
        /// <summary>
        /// Method Delete delete voting entity.
        /// </summary>
        /// <param name="entity">DalVoting entity.</param>
        public void Delete(DalVoting entity)
        {
            var vote = new Voting()
            {
                PhotoId = entity.PhotoId,
                UserId  = entity.UserId
            };

            context.Set <Voting>().Remove(vote);
        }
        /// <summary>
        /// Method Create create voting entity.
        /// </summary>
        /// <param name="dalVoting">New voting entity for create.</param>
        public void Create(DalVoting dalVoting)
        {
            var voting = new Voting()
            {
                UserId  = dalVoting.UserId,
                PhotoId = dalVoting.PhotoId,
                Rating  = dalVoting.Rating
            };

            context.Set <Voting>().Add(voting);
        }
        /// <summary>
        /// Method Update update exists voting.
        /// </summary>
        /// <param name="dalVoting">DalVoting that need update.</param>
        public void Update(DalVoting dalVoting)
        {
            var vote = context.Set <Voting>().Where(photo => photo.PhotoId == dalVoting.PhotoId).Where(user => user.UserId == dalVoting.UserId).FirstOrDefault();

            Voting original = new Voting()
            {
                PhotoId = vote.PhotoId,
                UserId  = vote.UserId,
                Rating  = vote.Rating
            };

            context.Set <Voting>().Attach(original);

            vote.Rating = dalVoting.Rating;
            context.SaveChanges();
        }