public ActionResult Product(ProductViewModel productViewModel) { if (productViewModel == null) { return(this.HttpNotFound()); } if (this.ModelState.IsValid) { repository.UpdateOrCreateNewProduct(new Product() { Id = productViewModel.Id, Name = productViewModel.Name, Description = productViewModel.Description, IsAvailable = productViewModel.IsAvailable, PriceCurrencyId = productViewModel.CurrencyId, PriceValueCash = new Decimal(productViewModel.PriceCash), PriceValueCashless = new Decimal(productViewModel.PriceCashless) }, productViewModel.ParentCategoryId, productViewModel.Images, productViewModel.TemplateId, productViewModel.Attributes, productViewModel.Position); return(this.RedirectToAction("Pages", new { treeSelection = productViewModel.ParentCategoryId })); } else { this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); return(this.View(productViewModel)); } }
public ActionResult Pages(Guid?treeSelection) { this.ViewData["SettingsViewModel"] = this.settingsViewModel; this.ViewData["MainMenuViewModel"] = MenuViewModelFactory.CreateAdminMenu(repository, ControlPanelPage.Pages); this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); this.ViewData["TreeSelection"] = treeSelection; return(this.View(new PageViewModel())); }
public ActionResult Category(Guid?id, Guid?parentId) { this.ViewData["SettingsViewModel"] = this.settingsViewModel; this.ViewData["MainMenuViewModel"] = MenuViewModelFactory.CreateAdminMenu(repository, ControlPanelPage.Pages); this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); var categoryViewModel = id != null ? new CategoryViewModel(this.repository, id.Value) : new CategoryViewModel(); categoryViewModel.Content.ParentCategoryId = parentId ?? Guid.Empty; return(this.View("Category", categoryViewModel)); }
public ActionResult Product(Guid?id, Guid?parentId) { var viewModel = id != null && id != Guid.Empty ? new ProductViewModel(this.repository, id.Value, parentId, null) : new ProductViewModel(this.repository, parentId); viewModel.InitializeRootCategory(this.repository); this.ViewData["MainMenuViewModel"] = MenuViewModelFactory.CreateAdminMenu(repository, ControlPanelPage.Pages); this.ViewData["SettingsViewModel"] = this.settingsViewModel; this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); return(this.View("Product", viewModel)); }
public ActionResult Page(Guid?id, Guid?parentId, string a, string c = null) { if (!string.IsNullOrEmpty(a) && id != null && id != Guid.Empty) { if (string.Equals("delete", a, StringComparison.OrdinalIgnoreCase)) { this.repository.DeletePage(id.Value); return(this.RedirectToAction("Pages", new { treeSelection = parentId != null ? parentId.Value : Guid.Empty })); } if (string.Equals("moveup", a, StringComparison.OrdinalIgnoreCase)) { this.repository.ChangePagePosition(id.Value, false); return(this.RedirectToAction("Pages", new { treeSelection = id.Value })); } if (string.Equals("movedown", a, StringComparison.OrdinalIgnoreCase)) { this.repository.ChangePagePosition(id.Value, true); return(this.RedirectToAction("Pages", new { treeSelection = id.Value })); } } if (id == Guid.Empty) { return(this.RedirectToAction("Settings", new { t = "main" })); } if (c == "p") { return(this.Product(id, parentId)); } var pageViewModel = id != null ? new PageViewModel(this.repository, id.Value) : new PageViewModel() { ParentCategoryId = parentId ?? Guid.Empty }; if (pageViewModel.ContentPage != null && pageViewModel.ContentPage.IsCategory()) { return(this.Category(id, parentId ?? pageViewModel.ParentCategoryId)); } else { this.ViewData["SettingsViewModel"] = this.settingsViewModel; this.ViewData["MainMenuViewModel"] = MenuViewModelFactory.CreateAdminMenu(repository, ControlPanelPage.Pages); this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); return(this.View(pageViewModel)); } }
public ActionResult Page(PageViewModel pageViewModel) { Guid?parentId = pageViewModel.ParentCategoryId == Guid.Empty ? (Guid?)null : pageViewModel.ParentCategoryId; if (parentId != null && pageViewModel.Id != null && pageViewModel.Id != Guid.Empty && ValidateParentId(parentId.Value, pageViewModel.Id)) { this.ModelState.AddModelError("ParentCategoryId", StringResource.admin_CantAddPageToItselfParent); } var attachmentIds = pageViewModel.Attachments != null && pageViewModel.Attachments.Any() ? pageViewModel.Attachments.Select(x => x.AttachmentId.Value).ToList() : null; if (this.ModelState.IsValid) { var contentPage = pageViewModel.Id != Guid.Empty ? this.repository.GetPageById(pageViewModel.Id) : null; if (contentPage == null) { contentPage = new ContentPage { Name = pageViewModel.Name, Text = pageViewModel.Text, ParentId = parentId, ShowInMenu = pageViewModel.ShowInMenu, Position = repository.GetPages(parentId, null).Count, }; repository.NewPage(contentPage, attachmentIds); } else { contentPage.Name = pageViewModel.Name; contentPage.Text = pageViewModel.Text; contentPage.ParentId = parentId; contentPage.ShowInMenu = pageViewModel.ShowInMenu; this.repository.UpdateContentPage(contentPage, attachmentIds); } return(this.RedirectToAction("Pages", new { treeSelection = contentPage.Id })); } else { this.ViewData["SettingsViewModel"] = this.settingsViewModel; this.ViewData["MainMenuViewModel"] = MenuViewModelFactory.CreateAdminMenu(repository, ControlPanelPage.Pages); this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); return(this.View(pageViewModel ?? new PageViewModel())); } }
public ActionResult ImportProducts(Guid parentId) { this.ViewData["ParentCategory"] = parentId; this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); return(this.View()); }
public ActionResult Category(CategoryViewModel categoryViewModel) { Guid?parentId = categoryViewModel.Content.ParentCategoryId == Guid.Empty ? (Guid?)null : categoryViewModel.Content.ParentCategoryId; if (parentId != null && categoryViewModel.Content.Id != null && categoryViewModel.Content.Id != Guid.Empty && ValidateParentId(parentId.Value, categoryViewModel.Content.Id)) { this.ModelState.AddModelError("ParentCategoryId", StringResource.admin_CantAddPageToItselfParent); } if (this.ModelState.IsValid) { Guid pageId = categoryViewModel.Content.Id; if (categoryViewModel.Content.Id != Guid.Empty) { var contentPage = repository.GetPageById(categoryViewModel.Content.Id); if (contentPage == null || contentPage.CategoryId == null) { throw new InvalidOperationException(string.Format("Model is invalid state. Category for guid {0} has not been found.", categoryViewModel.Content.Id)); } contentPage.Name = categoryViewModel.Content.Name; contentPage.Text = categoryViewModel.Content.Text; contentPage.ShowInMenu = categoryViewModel.Content.ShowInMenu; contentPage.ParentId = parentId; repository.UpdateContentPage(contentPage, null); var category = repository.GetCategoryById(contentPage.CategoryId.Value); category.Name = categoryViewModel.Content.Name; category.ListType = categoryViewModel.ListType; category.Description = categoryViewModel.Content.Text; category.ImageId = categoryViewModel.CategoryImage; category.IsImportant = categoryViewModel.IsImportant; repository.UpdateCategory(category); } else { var categoryId = repository.NewCategory(new Category() { Name = categoryViewModel.Content.Name, ListType = categoryViewModel.ListType, Description = categoryViewModel.Content.Text, ImageId = categoryViewModel.CategoryImage, }); pageId = repository.NewPage(new ContentPage { Name = categoryViewModel.Content.Name, Text = categoryViewModel.Content.Text, ShowInMenu = categoryViewModel.Content.ShowInMenu, ParentId = parentId, Position = repository.GetPages(parentId, null).Count + 1, CategoryId = categoryId, }, null); } return(this.RedirectToAction("Pages", new { treeSelection = pageId })); } else { this.ViewData["SettingsViewModel"] = this.settingsViewModel; this.ViewData["MainMenuViewModel"] = MenuViewModelFactory.CreateAdminMenu(repository, ControlPanelPage.Pages); this.ViewData["CategoryTreeRootViewModel"] = CategoryTreeItemViewModel.CreateNavigationTree(repository); return(this.View(categoryViewModel ?? new CategoryViewModel())); } }