Beispiel #1
0
 public HttpResponseMessage GetTopMoviesByUserRating(string userId = null)
 {
     try
     {
         ComcastMoviesApplication.Helpers.ValidationHelper vHelper = new ComcastMoviesApplication.Helpers.ValidationHelper();
         Guid?guid;
         if (!vHelper.IsValidGuid(userId, out guid))
         {
             return(new HttpResponseMessage(HttpStatusCode.NotFound));
         }
         if (!guid.HasValue)
         {
             throw new ArgumentNullException("Guid is null");
         }
         var movieRatings = movieService.GetTopMoviesByUserRating(guid.Value);
         IEnumerable <MovieViewModel> movieViewModels = new AggregateHelper().Aggregate(movieRatings);
         HttpResponseMessage          responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
         responseMessage.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(movieViewModels));
         return(responseMessage);
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage(HttpStatusCode.NotFound));
     }
 }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException("bindingContext");
            }

            _request = controllerContext.HttpContext.Request;
            var queryString = GetQueryString();

            var kendoGridRequest = new KendoGridMvcRequest
            {
                Take     = queryString.GetQueryValue("take", (int?)null),
                Page     = queryString.GetQueryValue("page", (int?)null),
                Skip     = queryString.GetQueryValue("skip", (int?)null),
                PageSize = queryString.GetQueryValue("pageSize", (int?)null),

                FilterObjectWrapper = FilterHelper.Parse(queryString),
                GroupObjects        = GroupHelper.Parse(queryString),
                AggregateObjects    = AggregateHelper.Parse(queryString),
                SortObjects         = SortHelper.Parse(queryString),
            };

            return(kendoGridRequest);
        }
        public static DocumentStore ConfigureForArkEventSourcing(this DocumentStore store)
        {
            var current = store.Conventions.FindCollectionName;

            store.Conventions.AddFindCollectionName(type =>
            {
                if (typeof(IOutboxEvent).IsAssignableFrom(type))
                {
                    return(RavenDbEventSourcingConstants.OutboxCollectionName);
                }

                if (typeof(AggregateEventStore <,>).IsAssignableFromEx(type) || typeof(AggregateEventStore).IsAssignableFrom(type))
                {
                    return(RavenDbEventSourcingConstants.AggregateEventsCollectionName);
                }

                if (typeof(AggregateState <,>).IsAssignableFromEx(type))
                {
                    while (!(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(AggregateState <,>)))
                    {
                        type = type.BaseType;
                    }

                    var aggregateName = AggregateHelper.AggregateName(type.GetGenericArguments()[0]);
                    return(aggregateName);
                }

                return(null);
            });

            store.Conventions.UseOptimisticConcurrency     = true;
            store.Conventions.ThrowIfQueryPageSizeIsNotSet = true;

            return(store);
        }
Beispiel #4
0
        public void GetAggregateTypes_should_return_all_aggregates()
        {
            var aggregates = AggregateHelper.GetAggregateTypes();

            aggregates.Should().Contain(new List <Type> {
                typeof(BankAccount)
            });
        }
        private byte[] InternalGeneratePdf <T>(Action <PdfWriter, Document> configureSettings, T model = null,
                                               string viewName = null, List <BasePageSnippet> pageSnippets = null, Margins margins = null)
            where T : class
        {
            ControllerContext.Controller.ViewData.Model = model;

            byte[] output;

            var document = margins == null
                ? new Document()
                : new Document(margins.PageSize, margins.Left, margins.Right, margins.Top, margins.Bottom);

            using (document)
            {
                using (var workStream = new MemoryStream())
                {
                    var writer = PdfWriter.GetInstance(document, workStream);
                    writer.CloseStream = false;

                    if (pageSnippets != null)
                    {
                        var aggregateHelper = new AggregateHelper(pageSnippets, InternalGeneratePdf);
                        writer.PageEvent = aggregateHelper;
                    }

                    configureSettings?.Invoke(writer, document);
                    document.Open();

                    using (var reader = new StringReader(RenderRazorView(viewName)))
                    {
                        var workerInstance = XMLWorkerHelper.GetInstance();

                        var tagProcessors = Tags.GetHtmlTagProcessorFactory();
                        if (!string.IsNullOrEmpty(ImageBasePath))
                        {
                            tagProcessors.RemoveProcessor(HTML.Tag.IMG);
                            tagProcessors.AddProcessor(new ImageTagProcessor(ImageBasePath), new[] { HTML.Tag.IMG });
                        }

                        var htmlContext = new HtmlPipelineContext(null);

                        htmlContext.SetTagFactory(tagProcessors);

                        var cssResolver = workerInstance.GetDefaultCssResolver(true);
                        var pipeline    = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));

                        var worker = new XMLWorker(pipeline, true);
                        var parser = new XMLParser(worker);
                        parser.Parse(reader);

                        document.Close();
                        output = workStream.ToArray();
                    }
                }
            }

            return(output);
        }
Beispiel #6
0
 public HttpResponseMessage GetTopMoviesByRating()
 {
     try
     {
         IEnumerable <MovieRating>    movieRatings    = movieService.GetTopMoviesByRating();
         IEnumerable <MovieViewModel> movieViewModels = new AggregateHelper().Aggregate(movieRatings);
         HttpResponseMessage          responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
         responseMessage.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(movieViewModels));
         return(responseMessage);
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage(HttpStatusCode.NotFound));
     }
 }
Beispiel #7
0
        private CustomApiRequest Parse(string jsonRequest)
        {
            var kendoJsonRequest = JsonConvert.DeserializeObject <CustomGridRequest>(jsonRequest);

            return(new CustomApiRequest
            {
                Custom = kendoJsonRequest.Custom,
                Take = kendoJsonRequest.Take,
                Page = kendoJsonRequest.Page,
                PageSize = kendoJsonRequest.PageSize,
                Skip = kendoJsonRequest.Skip,
                Logic = kendoJsonRequest.Logic,
                GroupObjects = GroupHelper.Map(kendoJsonRequest.Groups),
                AggregateObjects = AggregateHelper.Map(kendoJsonRequest.AggregateObjects),
                FilterObjectWrapper = FilterHelper.MapRootFilter(kendoJsonRequest.Filter),
                SortObjects = SortHelper.Map(kendoJsonRequest.Sort)
            });
        }
Beispiel #8
0
        public HttpResponseMessage FindMovies(string title = null, string yearOfRelease = null, string genre = null)
        {
            try
            {
                ComcastMoviesApplication.Helpers.ValidationHelper vHelper = new ComcastMoviesApplication.Helpers.ValidationHelper();
                if (!vHelper.IsValidFindMovieRequest(title, yearOfRelease, genre))
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }

                IEnumerable <MovieRating>    movieRatings    = movieService.FindMovie(title, yearOfRelease, genre);
                IEnumerable <MovieViewModel> movieViewModels = new AggregateHelper().Aggregate(movieRatings);
                HttpResponseMessage          responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
                responseMessage.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(movieViewModels));
                return(responseMessage);
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
        }
Beispiel #9
0
        public Task BindModelAsync([NotNull] ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            bool isForm = bindingContext.HttpContext.Request.HasFormContentType &&
                          bindingContext.HttpContext.Request.Method.ToUpper() == "POST";

            var collection = isForm ?
                             bindingContext.HttpContext.Request.Form as IEnumerable <KeyValuePair <string, StringValues> > :
                             bindingContext.HttpContext.Request.Query as IEnumerable <KeyValuePair <string, StringValues> >;

            var queryString = new NameValueCollection();

            foreach (KeyValuePair <string, StringValues> entry in collection)
            {
                string key   = entry.Key;
                string value = entry.Value.ToArray().FirstOrDefault();
                queryString.Add(key, value);
            }

            var kendoGridRequest = new KendoGridMvcRequest
            {
                Take     = queryString.GetQueryValue("take", (int?)null),
                Page     = queryString.GetQueryValue("page", (int?)null),
                Skip     = queryString.GetQueryValue("skip", (int?)null),
                PageSize = queryString.GetQueryValue("pageSize", (int?)null),

                FilterObjectWrapper = FilterHelper.Parse(queryString),
                GroupObjects        = GroupHelper.Parse(queryString),
                AggregateObjects    = AggregateHelper.Parse(queryString),
                SortObjects         = SortHelper.Parse(queryString),
            };

            bindingContext.Result = ModelBindingResult.Success(kendoGridRequest);

            return(Task.CompletedTask);
        }
Beispiel #10
0
        protected virtual IEnumerable <Type> DetectAggregates()
        {
            var aggregateTypes = AggregateHelper.GetAggregateTypes();

            return(aggregateTypes);
        }
Beispiel #11
0
        public void AggregateHelper_TestMapNull()
        {
            IEnumerable <AggregateObject> objects = AggregateHelper.Map(null);

            Assert.IsNull(objects);
        }