Exemplo n.º 1
0
 public ActionResult Edit(MailModel model, string action)
 {
     if (action == "Cancel")
     {
         if (TempData["referrer"] != null)
         {
             return(Redirect(TempData["referrer"].ToString()));
         }
         return(RedirectToAction("Index"));
     }
     if (ModelState.IsValid)
     {
         if (model.Mail == null)
         {
             RedirectToAction("Index");
         }
         MailRepository rep = new MailRepository();
         if (action == "Save")
         {
             if (rep.ChangeMail(model.Mail))
             {
                 TempData["message"] = string.Format("{0} has been saved", model.Mail.title);
             }
             else
             {
                 TempData["error"] = string.Format("{0} has not been saved!", model.Mail.title);
             }
         }
         if (action == "Remove")
         {
             if (rep.RemoveUser(model.Mail))
             {
                 TempData["message"] = string.Format("{0} has been removed", model.Mail.title);
             }
             else
             {
                 TempData["error"] = string.Format("{0} has not been removed!", model.Mail.title);
             }
         }
         if (TempData["referrer"] != null)
         {
             return(Redirect(TempData["referrer"].ToString()));
         }
         return(RedirectToAction("Index"));
     }
     else
     {
         model = new MailModel(model.Mail);
         return(View(model));
     }
 }