public static void AddRequest(Request item)
 {
     RequestDataSource reqDS = new RequestDataSource();
     RequestEntry request = new RequestEntry();
     Convert.CopyFields(item, request);
     reqDS.AddRequest(request);
 }
        public RequestsDataSource()
        {
            var rqds = new RequestDataSource();
            _requestsList = rqds.Select();

            var rds = new RateDataSource();
            _rates = rds.SelectAll();
            _rates = (from r in _rates select r);
        }
        public static IEnumerable<Request> GetRequests(string status, DateTime? postedFrom, DateTime? postedTo)
        {
            RequestDataSource reqDS = new RequestDataSource();
            DatasetInfoDataSource viewDs = new DatasetInfoDataSource();

            // We should use values SqlDateTime.MinValue otherwies exception during query execution
            //January 1, 1753.
            if (!postedFrom.HasValue)
                postedFrom = SqlDateTime.MinValue.Value;

            //December 31, 9999.
            if (!postedTo.HasValue)
                postedTo = DateTime.UtcNow;

            IQueryable<RequestEntry> requests = (status == "All") ? reqDS.SelectAllWithHidden() : reqDS.SelectAll();

            var datasetViews = viewDs.SelectAll();

            var requestList = (from req in requests
                               where
                               req.PostedDate >= postedFrom &&
                               req.PostedDate <= postedTo
                               select req).AsEnumerable();

            var result = (from request in requestList
                          join r1 in datasetViews on request.RowKey equals r1.RowKey into lstWithViews
                          from es2 in lstWithViews.DefaultIfEmpty()
                          select new Request
                          {
                              Name = request.Name,
                              Email = request.Email,
                              RequestID = request.RowKey,
                              Subject = request.Subject,
                              Description = request.Description,
                              Status = request.Status,
                              ReleaseDate = request.ReleaseDate,
                              PostedDate = request.PostedDate,
                              Links = request.Links,
                              DatasetLink = request.DatasetLink,
                              PositiveVotes = (es2 != null ? es2.PositiveVotes : 0),
                              NegativeVotes = (es2 != null ? es2.NegativeVotes : 0),
                              Views = es2 != null ? es2.views_total : 0,
                          });

            return result;
        }
        public static Request GetRequest(string requestId)
        {
            RequestDataSource reqDS = new RequestDataSource();
            DatasetInfoDataSource viewDs = new DatasetInfoDataSource();
            RequestEntry req = reqDS.GetById(requestId);
            AnalyticInfo dsInfo = viewDs.GetAnalyticSummary(Helper.GenerateRequestKey(requestId));

            return new Request()
            {
                DatasetLink = req.DatasetLink,
                Description = req.Description,
                Links = req.Links,
                NegativeVotes = dsInfo.NegativeVotes,
                PositiveVotes = dsInfo.PositiveVotes,
                PostedDate = req.PostedDate,
                ReleaseDate = req.ReleaseDate,
                Status = req.Status,
                Subject = req.Subject,
                Views = dsInfo.views_total,
                RequestID = req.RowKey
            };
        }
        private static IEnumerable<Comment> CreateCommentEnumerator(IEnumerable<CommentEntry> comments)
        {
            var reqDS = new RequestDataSource();
            var requests = reqDS.Select().ToDictionary(t => t.RowKey, t => t.Subject);

            var entities = new Dictionary<String, String>();

            foreach(EntitySet e in EntitySetRepository.GetEntitySets())
                entities[e.ContainerAlias + e.EntitySetName] = e.Name;

            return (from comm in comments
                    select new Comment()
                    {
                        RowKey = comm.RowKey,
                        Author = comm.Username,
                        Body = comm.Comment,
                        ParentName = comm.DatasetId,
                        ParentType = comm.ParentType,
                        ParentContainer = comm.PartitionKey,
                        ParentDisplay = GetParentDisplayName(comm, requests, entities),
                        Posted = comm.PostedOn,
                        Status = comm.Status,
                        Subject = comm.Subject,
                        Type = comm.Type,
                        Email = comm.Email
                    }).OrderBy(t => t.Posted);
        }
 public static void DeleteRequest(string requestID)
 {
     RequestDataSource reqDS = new RequestDataSource();
     reqDS.DeleteRequest(requestID);
 }
 public static void UpdateRequest(Request item)
 {
     RequestDataSource reqDS = new RequestDataSource();
     RequestEntry request = reqDS.GetById(item.RequestID);
     Convert.CopyFields(item, request);
     reqDS.UpdateRequest(request);
 }