示例#1
0
        public async Task <IActionResult> AddProperty(string UrlTitle, NewCategoryPropertyViewModel model)
        {
            if (model == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            if (context.Categories.Find(model.CategoryId) == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                Property prop = new Property()
                {
                    Name = new TranslationEntry()
                    {
                        NeutralValue       = model.PropertyNeutralValue,
                        NeutralDescription = NeutralTitleDescription,
                        Translations       = new List <Translation>()
                        {
                            new Translation()
                            {
                                Value        = model.PropertyNeutralValue,
                                LanguageCode = NeutralLanguageCode
                            }
                        }
                    },
                    Description = new TranslationEntry()
                    {
                        NeutralValue       = model.PropertyNeutralDescription,
                        NeutralDescription = NeutralDescriptionDescription,
                        Translations       = new List <Translation>()
                        {
                            new Translation()
                            {
                                Value        = model.PropertyNeutralDescription,
                                LanguageCode = NeutralLanguageCode
                            }
                        }
                    },
                    IsRequired = model.PropertyIsRequired
                };
                context.CategoryProperties.Add(
                    new CategoryProperty()
                {
                    CategoryId = model.CategoryId,
                    Property   = prop
                }
                    );
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(ManagePropertyTranslations), new { PropertyId = prop.Id, CategoryId = model.CategoryId }));
            }
            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> AddProperty(string UrlTitle)
        {
            long?categoryId = context.Categories
                              .Where(cat => cat.UrlTitle == UrlTitle)
                              .Select(cat => cat.Id)
                              .SingleOrDefault();

            if (categoryId == null)
            {
                return(NotFound());
            }
            NewCategoryPropertyViewModel model = new NewCategoryPropertyViewModel()
            {
                CategoryId = (long)categoryId, UrlTitle = UrlTitle
            };

            return(View(model));
        }