Пример #1
0
        public ActionResult Create()
        {
            var country = this.CountryService.Create();
            var privilege = new CountryPrivilege();

            return privilege.CanCreate(country) ? base.View(Views.Create, new CountryCreateOrUpdate()) : NotAuthorized();
        }
Пример #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);
        }
Пример #3
0
        public ActionResult Index(SortCountry sort, SortOrder order, int? page)
        {
            var countries = this.CountryService.GetPaged(new CountrySpecification
            {
                Page = page,
                Limit = Setting.CountryPageLimit.Value,
                Sort = sort,
                Order = order
            });

            var country = countries.FirstOrDefault();
            var privilege = new CountryPrivilege();

            return privilege.CanView(country) ? base.View(Views.Index, countries) : NotAuthorized();
        }
Пример #4
0
        public ActionResult Update(int id)
        {
            var country = this.CountryService.GetById(id);

            if (country == null)
            {
                return HttpNotFound();
            }

            var privilege = new CountryPrivilege();

            return privilege.CanUpdate(country) ? base.View(Views.Update, new CountryCreateOrUpdate(country)) : NotAuthorized();
        }
Пример #5
0
        public ActionResult Delete(CountryDelete value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var country = this.CountryService.GetById(value.Id);

            if (country == null)
            {
                return HttpNotFound();
            }

            var privilege = new CountryPrivilege();

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

            this.CountryService.Delete(country);

            return base.RedirectToRoute(AdministrationRoutes.CountryIndex);
        }