public void FromEntity_should_map_properties()
        {
            var categoryEntity = new Category {Name = "Category 1", Description = "Category 1 Description"};
            var category = new EditCategory();

            category.FromEntity(categoryEntity);

            Assert.That(category.Name, Is.EqualTo(categoryEntity.Name));
            Assert.That(category.Description, Is.EqualTo(categoryEntity.Description));
        }
Exemple #2
0
        public Category ToEntity()
        {
            var category = new Category
                               {
                                   Id = this.Id,
                                   Name = this.Name,
                                   Description = this.Description
                               };

            return category;
        }
        public ActionResult Add(EditCategory category)
        {
            var categoryEntity = new Category();
            if (ModelState.IsValid)
            {
                categoryEntity = category.ToEntity();
                if (!categoryService.TryAdd(categoryEntity))
                {
                    AddModelStateErrors(categoryEntity.Errors);
                }
            }

            if (!ModelState.IsValid)
            {
                ViewBag.Title = Localisation.Admin.PageContent.Add;
                ViewBag.Category = Localisation.Admin.PageContent.Category;
                return View("Edit", category);
            }

            return RedirectToAction("Edit", new {id = categoryEntity.Id});
        }
        public JsonResult _Add(EditCategory category)
        {
            var categoryEntity = new Category();
            if (ModelState.IsValid)
            {
                categoryEntity = category.ToEntity();
                if (!categoryService.TryAdd(categoryEntity))
                {
                    AddModelStateErrors(categoryEntity.Errors);
                }
            }

            if (!ModelState.IsValid)
            {
                return Json(categoryEntity.Errors);
            }

            return Json(categoryEntity.Id);
        }
 public bool TryAdd(Category category)
 {
     if (IsValid(category))
     {
         repository.Add(category);
         return true;
     }
     return false;
 }
        private bool IsValid(Category category)
        {
            if (CategoryNameExists(category))
            {
                category.AddError(new ErrorInfo("Name", Localisation.ViewModels.EditCategory.CategoryExists));
            }

            return !category.Errors.Any();
        }
        private bool CategoryNameExists(Category category)
        {
            var searchCriteria = DetachedCriteria.For(typeof (Category))
                .Add(!Restrictions.Eq("Id", category.Id))
                .Add(Restrictions.Eq("Name", category.Name));

            var categoriesWithSameNameAndDifferentIds = repository.Count(searchCriteria);
            return categoriesWithSameNameAndDifferentIds > 0;
        }
 public bool TryUpdate(Category category)
 {
     throw new NotImplementedException();
 }
        public void ThisMethod_should_create_data_for_ChopShop_when_it_is_executed()
        {
            using (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))
            {
                // Create Categories
                var engines = new Category { Name = "Engines", Description = "All the engines you can imagine" };
                var tyres = new Category { Name = "Tyres", Description = "We have round tyres and square tyres!" };
                var parts = new Category { Name = "Body Parts", Description = "Doors, Wings and all sorts of Panels" };
                var cars = new Category { Name = "Cars", Description = "All shapes, most sizes, lots of prices" };
                var lorries = new Category { Name = "Lorries", Description = "Red ones, Yellow ones and even Blue ones" };
                var bicycles = new Category
                                   {
                                       Name = "Bicycles",
                                       Description = "Some of these have two wheels - some have only one"
                                   };
                var bicycleParts = new Category { Name = "Bicycle Parts", Description = "Derailleurs, Gears, Pedals" };

                engines.Parent = cars;
                tyres.Parent = cars;
                bicycleParts.Parent = bicycles;
                parts.Parent = lorries;

                var categories = new List<Category>
                                     {
                                         engines,
                                         tyres,
                                         parts,
                                         cars,
                                         lorries,
                                         bicycles,
                                         bicycleParts
                                     };
                foreach (var category in categories)
                {
                    session.Save(category);
                }

                // Create Products
                var bluepedal = new Product
                                    {
                                        Name = "Blue Pedal",
                                        Description = "This pedal is blue",
                                        Quantity = 10,
                                        Sku = "BluePedal0001"
                                    };
                var redpedal = new Product
                                   {
                                       Name = "Red Pedal",
                                       Description = "This pedal is red",
                                       Quantity = 3,
                                       Sku = "RedPedal0002"
                                   };
                var bigEngine = new Product
                                    {
                                        Name = "3.0 L V12",
                                        Description = "This is a fast one",
                                        Sku = "Eng00v12",
                                        Quantity = 2
                                    };

                var products = new List<Product> { bluepedal, redpedal, bigEngine };
                products.AddRange(GetProducts());
                foreach (var product in products)
                {
                    session.Save(product);
                }

                // Associate Categories To Products
                bicycleParts.Products = new List<Product> { bluepedal, redpedal };
                engines.Products = new List<Product> { bigEngine };

                session.SaveOrUpdate(bicycleParts);
                session.SaveOrUpdate(engines);

                var adminUser = new AdminUser { Email = "*****@*****.**", Name = "admin", Password = "******" };
                session.SaveOrUpdate(adminUser);

                tx.Commit();
            }
        }
Exemple #10
0
 public void FromEntity(Category categoryEntity)
 {
     Id = categoryEntity.Id;
     Name = categoryEntity.Name;
     Description = categoryEntity.Description;
 }