public ViewResult Add()
 {
     var product = new EditProduct();
     ViewBag.Title = Localisation.Admin.PageContent.Add;
     ViewBag.Product = Localisation.Admin.PageContent.Product;
     ViewBag.ViewType = "Add";
     return View("Edit", product);
 }
        public void ToEntity_should_map_properties_when_invoked()
        {
            var editProduct = new EditProduct {Name = "Product Name", Description = "Product Description", Sku = "123"};

            var product = editProduct.ToEntity();

            Assert.That(product.Name, Is.EqualTo(editProduct.Name));
            Assert.That(product.Description, Is.EqualTo(editProduct.Description));
            Assert.That(product.Sku, Is.EqualTo(editProduct.Sku));
        }
        public void FromEntity_should_map_properties_when_invoked()
        {
            var fakeProduct = Fakes.FakeProduct();
            var editProduct = new EditProduct();

            editProduct.FromEntity(fakeProduct);

            Assert.That(editProduct.Name, Is.EqualTo(fakeProduct.Name));
            Assert.That(editProduct.Description, Is.EqualTo(fakeProduct.Description));
            Assert.That(editProduct.Sku, Is.EqualTo(fakeProduct.Sku));
        }
        public ActionResult Add(EditProduct product)
        {
            var productEntity = new Product();
            if (ModelState.IsValid) // validate inputs first
            {
                productEntity = product.ToEntity();
                if (!productService.TryAdd(productEntity)) // validate business logic
                {
                    AddModelStateErrors(productEntity.Errors);
                }
            }

            if (!ModelState.IsValid)
            {
                ViewBag.Title = Localisation.Admin.PageContent.Add;
                ViewBag.Product = Localisation.Admin.PageContent.Product;
                ViewBag.ViewType = "Add";
                return View("Edit", product);
            }
            return RedirectToAction("Edit", new { id = productEntity.Id });
        }
        public ViewResult DeleteConfirmation(Guid id, int page = 0, int perPage = 25, string orderBy = null, string asc = "true")
        {
            var productEntity = productService.GetSingle(id) ?? new Product();

            if (productEntity.Id == Guid.Empty)
            {
                ModelState.AddModelError("", Localisation.ViewModels.EditProduct.ProductNotFound);
            }

            var product = new EditProduct();
            product.FromEntity(productEntity);
            ViewBag.Title = Localisation.Admin.PageContent.Delete;
            ViewBag.Product = Localisation.Admin.PageContent.Product;
            ViewBag.ViewType = "Delete";
            return View(product);
        }
        public ViewResult Edit(Guid id)
        {
            var productEntity = productService.GetSingle(id) ?? new Product();

            if (productEntity.Id == Guid.Empty)
            {
                ModelState.AddModelError("", Localisation.ViewModels.EditProduct.ProductNotFound);
            }

            var product = new EditProduct();
            product.FromEntity(productEntity);
            ViewBag.Title = Localisation.Admin.PageContent.Edit;
            ViewBag.Product = Localisation.Admin.PageContent.Product;
            ViewBag.ViewType = "Edit";
            return View(product);
        }