public ActionResult Edit(int id, UpdateContactForm form)
        {
            if (id != form.Id)
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Command command = new Command("CSP_UpdateContact", true);
                    command.AddParameter("Id", id);
                    command.AddParameter("LastName", form.LastName);
                    command.AddParameter("FirstName", form.FirstName);
                    command.AddParameter("Email", form.Email);
                    command.AddParameter("Phone", form.Phone);
                    command.AddParameter("BirthDate", form.BirthDate);
                    command.AddParameter("CustomerId", _sessionManager.Customer.Id);
                    _connection.ExecuteNonQuery(command);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    //ViewBag.Error = ex.Message;
                }
            }

            return(View(form));
        }
 public static Contact ToContact(this UpdateContactForm entity)
 {
     return(new Contact()
     {
         Id = entity.Id, LastName = entity.LastName, FirstName = entity.FirstName, Email = entity.Email, Phone = entity.Phone
     });
 }
Ejemplo n.º 3
0
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            DataGridViewRow viewRow       = phonebookGridView.SelectedRows[0];
            var             contact       = Phonebook.Contacts.Where(c => c.Id == int.Parse(viewRow.Cells["Id"].Value.ToString())).FirstOrDefault();
            var             updateContact = new UpdateContactForm(contact);

            updateContact.Show();
        }
Ejemplo n.º 4
0
 public IActionResult Put(int customerId, int id, [FromBody] UpdateContactForm form)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _repository.Update(id, new Contact(form.LastName, form.FirstName, form.Email, form.Phone, form.BirthDate, customerId));
             return(NoContent());
         }
         return(BadRequest());
     }
     catch (Exception)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Ejemplo n.º 5
0
        public ActionResult Edit(int id, UpdateContactForm form)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (_contactRepository.Update(id, new Contact(form.LastName, form.FirstName, form.Email, SessionManager.User.Id, form.Phone)))
                    {
                        return(RedirectToAction("Index"));
                    }

                    ViewBag.Error = "Oups something wrong!!";
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                }
            }

            return(View(form));
        }
Ejemplo n.º 6
0
        public ActionResult Edit(int id, UpdateContactForm form)
        {
            if (ModelState.IsValid)
            {
                if (id == form.Id)
                {
                    Contact contact = new Contact()
                    {
                        Id = form.Id, LastName = form.LastName, FirstName = form.FirstName, Email = form.Email, Phone = form.Phone, Birthdate = form.Birthdate
                    };
                    _repository.Update(id, contact);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Edit", new { id = form.Id }));
                }
            }

            return(View(form));
        }
        public ActionResult Edit(int id, UpdateContactForm form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ServicesLocator.Instance.ContactService.Update(SessionManager.User.Id, id, form.ToContact());
                    return(RedirectToAction(nameof(Index)));
                }

                return(View(form));
            }
            catch (Exception ex)
            {
#if DEBUG
                ViewBag.Error = ex.Message;
#else
                ViewBag.Error = "Une erreur est survenue durant la mise à jour veuillez contacter l'administrateur du site";
#endif
                return(View(form));
            }
        }
        public ActionResult Edit(int id, UpdateContactForm form)
        {
            if (id != form.Id)
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _contactRepository.Update(id, new Contact(form.LastName, form.FirstName, form.Email, form.Phone, form.BirthDate, _sessionManager.Customer.Id));
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    //ViewBag.Error = ex.Message;
                }
            }

            return(View(form));
        }