示例#1
0
        public static Review[] GetReviewByUser(UserCritic user)
        {
            lock (_locker)
            {
                List <Review> result = new List <Review>();

                _dataAdapter.SelectCommand.CommandText = "SELECT * FROM " + _tableName + " WHERE UserId=@id";

                if (!_dataAdapter.SelectCommand.Parameters.Contains("@id"))
                {
                    _dataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@id", user.Id));
                }
                else
                {
                    _dataAdapter.SelectCommand.Parameters["@id"].Value = user.Id;
                }

                _dataAdapter.Fill(_dataTable);
                var selectedRows = from row in _dataTable.AsEnumerable().AsParallel()
                                   where (Guid)row["UserId"] == user.Id
                                   select row;
                foreach (DataRow dr in selectedRows)
                {
                    result.Add(new Review(dr));
                }

                if (result.Count != 0)
                {
                    return(result.ToArray());
                }
                return(null);
            }
        }
示例#2
0
 public Review(UserCritic userCritic, Entertainment entertainment, byte point, string opinion, DateTimeOffset time,
               string link, string publication, int helpful, int unhelpful, bool checkedByAdmin) : base()
 {
     UserId          = userCritic.Id;
     EntertainmentId = entertainment.Id;
     Point           = point;
     Opinion         = opinion;
     Time            = time;
     Link            = link;
     Publication     = publication;
     Helpful         = helpful;
     Unhelpful       = unhelpful;
     CheckedByAdmin  = checkedByAdmin;
 }
示例#3
0
        public static Review GetReviewByEntertainmentAndUser(Entertainment entertainment, UserCritic user)
        {
            lock (_locker)
            {
                var query = from row in _dataTable.AsEnumerable().AsParallel()
                            where (Guid)row["EntertainmentId"] == entertainment.Id && (Guid)row["UserId"] == user.Id
                            select row;
                DataRow[] result = query.ToArray();
                if (result.Length == 1)
                {
                    return(new Review(result[0]));
                }
                else
                {
                    _dataAdapter.SelectCommand.CommandText = "SELECT * FROM " + _tableName + " WHERE EntertainmentId=@entertainmentId AND UserId=@userId;";

                    if (!_dataAdapter.SelectCommand.Parameters.Contains("@entertainmentId"))
                    {
                        _dataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@entertainmentId", entertainment.Id));
                    }
                    else
                    {
                        _dataAdapter.SelectCommand.Parameters["@entertainmentId"].Value = entertainment.Id;
                    }
                    if (!_dataAdapter.SelectCommand.Parameters.Contains("@userId"))
                    {
                        _dataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@userId", user.Id));
                    }
                    else
                    {
                        _dataAdapter.SelectCommand.Parameters["@userId"].Value = user.Id;
                    }

                    if (_dataAdapter.Fill(_dataTable) == 1)
                    {
                        var selectedRow = from row in _dataTable.AsEnumerable().AsParallel()
                                          where (Guid)row["EntertainmentId"] == entertainment.Id && (Guid)row["UserId"] == user.Id
                                          select row;
                        return(new Review(selectedRow.ToArray()[0]));
                    }
                    return(null);
                }
            }
        }