Esempio n. 1
0
 public ActionResult CreateEmployee(EmployeeModel newEmployee)
 {
     try
     {
         var Id = DBHelper.Instance.CreateEmployee(newEmployee);
         return Json(new { success = Messages.EmployeeCreatedSuccessfully, Id = Id });
     }
     catch (Exception ex)
     {
         return Json(new { errors = ex.Message });
     }
 }
Esempio n. 2
0
 public ActionResult UpdateEmployee(EmployeeModel model)
 {
     try
     {
         DBHelper.Instance.UpdateEmployee(model);
         return Json(new { success = Messages.EmployeeDetailsUpdatedSuccessfully });
     }
     catch (Exception ex)
     {
         return Json(new { errors = ex.Message });
     }
 }
Esempio n. 3
0
 public void UpdateEmployee(EmployeeModel model)
 {
     try
     {
         using (ProjectsDB db = new ProjectsDB())
         {
             var employee = db.Staff.Where(s => s.PersonId == model.PersonId).FirstOrDefault();
             employee.FirstName = model.FirstName;
             employee.Patronymic = model.Patronymic;
             employee.LastName = model.LastName;
             employee.Email = model.Email;
             db.Entry(employee).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new DBException("UpdateEmployee(): ", ex.ToString());
     }
 }
Esempio n. 4
0
 public int CreateEmployee(EmployeeModel model)
 {
     try
     {
         var Mapper = MapperHelper.CreateMap<EmployeeModel, Staff>();
         var employee = Mapper.Map<Staff>(model);
         using (ProjectsDB db = new ProjectsDB())
         {
             db.Staff.Add(employee);
             db.SaveChanges();
             return db.Staff.Where(s => s.Email == model.Email).Select(s => s.PersonId).FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
         throw new DBException("CreateEmployee(): ", ex.ToString());
     }
 }