Ejemplo n.º 1
0
        public async Task <IActionResult> EditPost(int id)
        {
            var  _ctxCupcakeToUpdate = _repository.GetCupcakeById(id);
            bool _ctxIsUpdated       = await TryUpdateModelAsync(_ctxCupcakeToUpdate, "", c => c.BakeryID, c => c.CupcakeType, c => c.Description, c => c.GlutenFree, c => c.Price);

            if (_ctxIsUpdated)
            {
                _repository.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }

            PopulateBakeriesDropDownList(_ctxCupcakeToUpdate.BakeryID);
            return(View(_ctxCupcakeToUpdate));
        }
Ejemplo n.º 2
0
 public async Task <IActionResult> EditPost(int id, Cupcake cupcake)
 {
     if (_repository.GetCupcakeById(id) is Cupcake cupcakeToUpdate)
     {
         if (await TryUpdateModelAsync(cupcakeToUpdate, prefix: "",
                                       c => c.BakeryId, c => c.CupcakeType, c => c.Description, c => c.GlutenFree, c => c.Price))
         {
             _repository.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
         PopulateBakeriesDropDownList(cupcakeToUpdate.BakeryId);
         return(View(cupcakeToUpdate));
     }
     return(NotFound());
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> EditPost(int id)
        {
            var  cupcakeToUpdate = _repository.GetCupcakeById(id);
            bool isUpdated       = await TryUpdateModelAsync <Cupcake>(
                cupcakeToUpdate,
                "",
                c => c.BakeryId,
                c => c.CupcakeType,
                c => c.Description,
                c => c.GlutenFree,
                c => c.Price);

            //c => c.CaloricValue); // añadir nuevo campo
            if (isUpdated == true)
            {
                _repository.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            PopulateBakeriesDropDownList(cupcakeToUpdate.BakeryId);
            return(View(cupcakeToUpdate));
        }