Пример #1
0
        public ActionResult Create()
        {
            var model = new BeerViewModelCreate();

            FillData(model, false);


            return(View(model));
        }
Пример #2
0
        public ActionResult Create(BeerViewModelCreate model)
        {
            if (ModelState.IsValid)
            {
                var StateCreate = _beerService.CreateBeer(model.ToBeerDto());

                if (StateCreate.State)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(GeneralConst.DuplicateName, "Duplicate Name");
                    FillData(model, true);
                    return(View(model));
                }
            }
            else
            {
                ModelState.AddModelError(GeneralConst.GenericError, "Some information is empty");
                FillData(model, true);
                return(View(model));
            }
        }
Пример #3
0
        private void FillData(BeerViewModelCreate model, bool reload)
        {
            model.BeerTypeDtoList = new List <SelectListItem> {
                //Nuevo elemento list, para mostrar como primer valor
                new SelectListItem
                {
                    Text  = "Select",
                    Value = "0"
                }
            }.Union(_beerTypeService.GetAll().ToSelectListItemList());

            model.CountryDtoList = new List <SelectListItem> {
                new SelectListItem
                {
                    Text  = "Select",
                    Value = "0"
                }
            }.Union(_countryService.GetAll().ToSelectListItemList());

            if (reload && model.CountryId != Guid.Empty)
            {
                model.CityDtoList = _cityService.GetByCountryId(model.CountryId).ToSelectListItemList();
            }
        }