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)); }
public async Task <IActionResult> Edit(long?Id, Category editedCategory) { if (!ModelState.IsValid) { return(View(editedCategory)); } Category category = context.Categories.FirstOrDefault(cat => cat.Id == Id); category.Title = editedCategory.Title; category.Description = editedCategory.Description; category.ImagePath = editedCategory.ImagePath; category.ParentId = editedCategory.ParentId; category.UrlTitle = editedCategory.UrlTitle; context.Categories.Update(category); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> New(Ad model) { if (ModelState.IsValid) { await context.Ads.AddAsync(model); await context.SaveChangesAsync(); var urlTitle = context.Categories.Find(model.CategoryId).UrlTitle; return(RedirectToAction(nameof(ShowAd), new { Category = urlTitle, AdId = model.Id })); } ViewData["Title"] = "Izvietot jaunu sludinājums"; List <Category> categories = context.Categories.ToList(); categories.Remove(categories.Where(cat => cat.Id == 1).FirstOrDefault()); List <Language> languages = context.Languages.ToList(); ViewBag.languages = languages; ViewBag.categories = categories; return(View(model)); }