コード例 #1
0
        public ActionResult Edit(AuteurEditViewModel model)
        {
            // Check if the provided data is valid, if not rerender the edit view
            // so the user can correct and resubmit the edit form
            if (ModelState.IsValid)
            {
                // Retrieve the employee being edited from the database
                Auteur auteur = auteurRepository.GetAuteur(model.Id);
                // Update the employee object with the data in the model object
                auteur.Nom    = model.Nom;
                auteur.Prenom = model.Prenom;


                // If the user wants to change the photo, a new photo will be
                // uploaded and the Photo property on the model object receives
                // the uploaded photo. If the Photo property is null, user did
                // not upload a new photo and keeps his existing photo


                Auteur updatedAuteur = auteurRepository.Update(auteur);
                if (updatedAuteur != null)
                {
                    return(RedirectToAction("index"));
                }
                else
                {
                    return(NotFound());
                }
            }

            return(View(model));
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            Auteur auteur = auteurRepository.GetAuteur(id);
            AuteurEditViewModel AuteurEditViewModel = new AuteurEditViewModel
            {
                Id     = auteur.Id,
                Nom    = auteur.Nom,
                Prenom = auteur.Prenom
            };

            return(View(AuteurEditViewModel));
        }