示例#1
0
        public async Task <IActionResult> Create([Bind("ID,Name,CountryID")] BreweryViewModel brewery)
        {
            if (ModelState.IsValid)
            {
                var newBrewery = await _service.CreateAsync(brewery.MapBreweryViewToDTO());

                //_context.Add(brewery);
                //await _context.SaveChangesAsync();
                brewery = newBrewery.MapBreweryDTOToView();
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryID"] = new SelectList(this._countryService.GetAllAsync().Result, "ID", "Name", brewery.Name);
            return(View(brewery));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,CountryID,IsDeleted")] BreweryViewModel brewery)
        {
            if (id != brewery.ID)
            {
                return(NotFound());
            }
            var updateModel = brewery.MapBreweryViewToDTO();

            if (ModelState.IsValid)
            {
                try
                {
                    await _service.UpdateAsync(id, updateModel);
                }
                catch (Exception)
                {
                    return(NotFound());
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryID"] = new SelectList(this._countryService.GetAllAsync().Result, "ID", "Name", brewery.CountryID);
            return(View(brewery));
        }