public async Task <ActionResult> Edit(int categoryId) { try { Category category = await _repository.GetAsync(categoryId); CategoryViewModel model = new CategoryViewModel { Id = category.Id, Name = category.Name, ParentId = (int)category.ParentId, Categories = await _repository.GetAllAsync() }; return(View(model: model, viewName: "Edit")); } catch (KeyNotFoundException e) { return(HttpNotFound()); } }
public async Task <ActionResult> Edit(int productId) { // TODO: to retrieve the model from the data store var product = await _productRepository.GetByIdAsync(productId); if (product == null) { return(HttpNotFound()); } var category = await _categoryRepostitory.GetAsync(product.CategoryId); var model = new ProductViewModel { Name = product.Name, Content = product.Content, Discount = product.Discount, Price = product.Price, CategoryId = product.CategoryId, CategoryName = true, AuthorId = product.AuthorId, FromDateDiscount = product.FromDateDiscount, ToDateDiscount = product.ToDateDiscount, SKU = product.SKU, Count = product.Count, ImageUrl = product.ImageUrl, Categories = await _categoryRepostitory.GetAllAsync() }; if (User.IsInRole("author")) { var user = await GetloggedInUser(); if (product.AuthorId != user.Id) { return(new HttpUnauthorizedResult()); } } return(View(model: model)); }