public MenuItemViewModel Create(MenuItem menuItem)
 {
     return(new MenuItemViewModel()
     {
         Name = this.RequestHandler.GetLocalizationValue(menuItem.NameId),
         Url = GlobalizedUrlFormatter.Format(this.RequestHandler.Storage, menuItem.Url),
         MenuItems = this.RequestHandler.Storage.GetRepository <IMenuItemRepository>().FilteredByMenuItemId(menuItem.Id).ToList().Select(
             mi => new MenuItemViewModelFactory(this.RequestHandler).Create(mi)
             )
     });
 }
Пример #2
0
 public MenuItemViewModel Create(HttpContext httpContext, MenuItem menuItem)
 {
     return(new MenuItemViewModel()
     {
         Name = menuItem.Name.GetLocalizationValue(),
         Url = GlobalizedUrlFormatter.Format(httpContext, menuItem.Url),
         MenuItems = menuItem.MenuItems == null?Array.Empty <MenuItemViewModel>() : menuItem.MenuItems.OrderBy(mi => mi.Position).Select(
                             mi => new MenuItemViewModelFactory().Create(httpContext, mi)
                             )
     });
 }
 public CategoryViewModel Create(HttpContext httpContext, Category category)
 {
     return(new CategoryViewModel()
     {
         Id = category.Id,
         Category = category.Owner == null ? null : new CategoryViewModelFactory().Create(httpContext, category.Owner),
         Url = GlobalizedUrlFormatter.Format(httpContext, category.Url),
         Name = category.Name.GetLocalizationValue(),
         Categories = category.Categories == null?Array.Empty <CategoryViewModel>() : category.Categories.OrderBy(c => c.Position).Select(
                              c => new CategoryViewModelFactory().Create(httpContext, c)
                              ).ToArray()
     });
 }
Пример #4
0
        public CatalogViewModel Create(Catalog catalog)
        {
            IEnumerable <Catalog> catalogs = this.RequestHandler.Storage.GetRepository <ICatalogRepository>().FilteredByCatalogId(catalog.Id).ToList();

            return(new CatalogViewModel()
            {
                Url = GlobalizedUrlFormatter.Format(this.RequestHandler, catalog.Url),
                Name = this.RequestHandler.GetLocalizationValue(catalog.NameId),
                Catalogs = catalogs.Select(
                    c => new CatalogViewModelFactory(this.RequestHandler).Create(c)
                    ).ToList()
            });
        }
Пример #5
0
        public IActionResult Index(IndexViewModel indexViewModel)
        {
            if (this.ModelState.IsValid)
            {
                Order order = new IndexViewModelMapper(this).Map(indexViewModel);

                this.Storage.GetRepository <IOrderRepository>().Create(order);
                this.Storage.Save();
                new CartManager(this).AssignTo(order);
                Event <IOrderCreatedEventHandler, IRequestHandler, Order> .Broadcast(this, order);

                return(this.Redirect(GlobalizedUrlFormatter.Format(this, "/ecommerce/checkout/done?orderid=" + order.Id)));
            }

            return(this.View(indexViewModel));
        }
        public MenuItemViewModel Create(SerializedMenuItem serializedMenuItem)
        {
            IEnumerable <SerializedMenuItem> cachedMenuItems = new SerializedMenuItem[] { };

            if (!string.IsNullOrEmpty(serializedMenuItem.SerializedMenuItems))
            {
                cachedMenuItems = JsonConvert.DeserializeObject <IEnumerable <SerializedMenuItem> >(serializedMenuItem.SerializedMenuItems);
            }

            return(new MenuItemViewModel()
            {
                Name = serializedMenuItem.Name,
                Url = GlobalizedUrlFormatter.Format(this.RequestHandler.Storage, serializedMenuItem.Url),
                MenuItems = cachedMenuItems.OrderBy(cmi => cmi.Position).Select(
                    cmi => new MenuItemViewModelFactory(this.RequestHandler).Create(cmi)
                    )
            });
        }
        // TODO: this code is ugly and must be rewritten using the strongly-typed mapper (when it is done)
        public async Task <IActionResult> HandleAsync(HttpContext httpContext, string origin, Form form, IDictionary <Field, string> valuesByFields, IDictionary <string, byte[]> attachmentsByFilenames)
        {
            Class @class = (await httpContext.GetStorage().GetRepository <int, Class, ClassFilter>().GetAllAsync(
                                new ClassFilter()
            {
                Code = "Comment"
            },
                                inclusions: new Inclusion <Class>(c => c.Members)
                                )).FirstOrDefault();

            Object commentObject = new Object();

            commentObject.ClassId = @class.Id;
            httpContext.GetStorage().GetRepository <int, Object, ObjectFilter>().Create(commentObject);
            await httpContext.GetStorage().SaveAsync();

            Property authorProperty = new Property();

            authorProperty.ObjectId    = commentObject.Id;
            authorProperty.MemberId    = @class.Members.First(m => m.Code == "Author").Id;
            authorProperty.StringValue = new Dictionary()
            {
                Localizations = new[] { new Localization()
                                        {
                                            CultureId = "__", Value = this.GetValueByFieldCode(valuesByFields, "Name")
                                        } }
            };
            httpContext.GetStorage().GetRepository <int, Property, PropertyFilter>().Create(authorProperty);

            Property textProperty = new Property();

            textProperty.ObjectId    = commentObject.Id;
            textProperty.MemberId    = @class.Members.First(m => m.Code == "Text").Id;
            textProperty.StringValue = new Dictionary()
            {
                Localizations = new[] { new Localization()
                                        {
                                            CultureId = "__", Value = this.GetValueByFieldCode(valuesByFields, "Comment")
                                        } }
            };
            httpContext.GetStorage().GetRepository <int, Property, PropertyFilter>().Create(textProperty);

            Property createdProperty = new Property();

            createdProperty.ObjectId      = commentObject.Id;
            createdProperty.MemberId      = @class.Members.First(m => m.Code == "Created").Id;
            createdProperty.DateTimeValue = System.DateTime.Now;
            httpContext.GetStorage().GetRepository <int, Property, PropertyFilter>().Create(createdProperty);

            Object postPageObject = (await httpContext.GetStorage().GetRepository <int, Object, ObjectFilter>().GetAllAsync(
                                         new ObjectFilter()
            {
                StringValue = new LocalizationFilter()
                {
                    Value = new StringFilter()
                    {
                        Equals = origin
                    }
                }
            },
                                         inclusions: new Inclusion <Object>[]
            {
                new Inclusion <Object>(o => o.Class.Members)
            }
                                         )).FirstOrDefault();

            Relation relation = new Relation();

            relation.MemberId  = postPageObject.Class.Members.First(m => m.Code == "Comments").Id;
            relation.PrimaryId = commentObject.Id;
            relation.ForeignId = postPageObject.Id;
            httpContext.GetStorage().GetRepository <int, Relation, RelationFilter>().Create(relation);
            await httpContext.GetStorage().SaveAsync();

            return(new RedirectResult(GlobalizedUrlFormatter.Format(httpContext, origin)));
        }