Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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 });
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }