Ejemplo n.º 1
0
        public void Test_CountryCreateOrUpdate_ValueToModel()
        {
            var value = new CountryCreateOrUpdate
            {
                Title = "test",
                Code = "test2"
            };

            var country = new Country();

            value.ValueToModel(country);

            Assert.AreEqual("test", country.Title, "Title");
            Assert.AreEqual("test2", country.Code, "Code");
        }
Ejemplo n.º 2
0
        public ActionResult Create(CountryCreateOrUpdate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var country = this.CountryService.Create();
            var privilege = new CountryPrivilege();

            if (!privilege.CanCreate(country))
            {
                return NotAuthorized();
            }

            value.Validate();

            if (value.IsValid)
            {
                value.ValueToModel(country);

                this.CountryService.InsertOrUpdate(country);

                value = new CountryCreateOrUpdate(country);
                value.SuccessMessage(Messages.CountryCreated.FormatInvariant(country.Title));
            }
            else
            {
                value.CopyToModel(ModelState);
            }

            return base.View(Views.Update, value);
        }