Ejemplo n.º 1
0
 public ActionResult Edit(Employee existingEmployee)
 {
     if (ModelState.IsValid)
     {
         try
         {
             LoadEmployeeImageToObject(existingEmployee);
             _dbContext.Entry(existingEmployee).State = EntityState.Modified;
             _dbContext.SaveChanges();
             this.ShowMessage("Employee saved successfully", MessageType.Success);
             return(RedirectToAction("Details", new { existingEmployee.Id }));
         }
         catch (Exception ex)
         {
             ModelState.AddModelError(
                 string.Empty, ExceptionDude.FormatMessage(ex));
         }
     }
     return(View(new EmployeeEditorModel(existingEmployee)));
 }
Ejemplo n.º 2
0
 public ActionResult Create(Employee newEmployee)
 {
     if (ModelState.IsValid)
     {
         try
         {
             LoadEmployeeImageToObject(newEmployee);
             _dbContext.EmployeeRepository.Add(newEmployee);
             _dbContext.SaveChanges();
             this.ShowMessage("Employee created successfully", MessageType.Success);
             return(RedirectToAction("Edit", new { newEmployee.Id }));
         }
         catch (Exception ex)
         {
             ModelState.AddModelError(
                 string.Empty, ExceptionDude.FormatMessage(ex));
         }
     }
     return(View("Edit", new EmployeeEditorModel(newEmployee)));
 }