public bool EditEmployeeService(RegisterEmpRequestModel employee)
        {
            try
            {
                int departmentId = db.Departments.Where(x => x.DeptName == employee.Department).Select(x => x.DeptId).FirstOrDefault();

                Employee emp = db.Employees.Find(employee.EmpId);
                emp.Name         = employee.Name;
                emp.SalaryId     = Convert.ToInt32(employee.SalaryId);
                emp.StartDate    = employee.StartDate;
                emp.Description  = employee.Description;
                emp.Gender       = employee.Gender;
                emp.DepartmentId = departmentId;

                //db.Entry(emp).State = EntityState.Modified;

                int result = db.SaveChanges();
                if (result > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public bool RegisterEmployeeService(RegisterEmpRequestModel employee)
 {
     try
     {
         Employee validEmployee = db.Employees.Where(x => x.Name == employee.Name && x.Gender == employee.Gender).FirstOrDefault();
         if (validEmployee == null)
         {
             int      departmentId = db.Departments.Where(x => x.DeptName == employee.Department).Select(x => x.DeptId).FirstOrDefault();
             Employee newEmployee  = new Employee()
             {
                 Name         = employee.Name,
                 Gender       = employee.Gender,
                 DepartmentId = departmentId,
                 SalaryId     = Convert.ToInt32(employee.SalaryId),
                 StartDate    = employee.StartDate,
                 Description  = employee.Description
             };
             Employee returnData = db.Employees.Add(newEmployee);
         }
         int result = db.SaveChanges();
         if (result > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #3
0
        public ActionResult EditEmployee(RegisterEmpRequestModel employee)
        {
            bool result = false;

            if (ModelState.IsValid)
            {
                result = this.empService.EditEmployee(employee);
            }
            return(RedirectToAction("EmployeeList"));
        }
 public bool RegisterEmployee(RegisterEmpRequestModel employee)
 {
     try
     {
         return(this.empService.RegisterEmployee(employee));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #5
0
        // GET: Employee/Edit/5
        public ActionResult Edit(RegisterEmpRequestModel model)
        {
            var sessionStorage = this.Session["LoginMail"] as string;

            if (sessionStorage != null)
            {
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
        /// <summary>
        /// Edit the existing employee details and update the data in database
        /// </summary>
        /// <param name="employee"></param>
        /// <returns></returns>
        public ActionResult EditEmployee(RegisterEmpRequestModel employee)
        {
            bool result = EditEmployeeService(employee);

            if (result == true)
            {
                List <EmployeeViewModel> list = GetAllEmployee();
                return(View("EmployeeList", list));
            }
            else
            {
                return(View("Error"));
            }
        }
        public ActionResult Edit(EmployeeDetailModel item)
        {
            RegisterEmpRequestModel emp = new RegisterEmpRequestModel();

            emp.EmpId       = item.EmpId;
            emp.Name        = item.Name;
            emp.Gender      = item.Gender;
            emp.Department  = item.Department;
            emp.SalaryId    = item.SalaryId.ToString();
            emp.StartDate   = item.StartDate;
            emp.Description = item.Description;

            return(View(emp));
        }
        //Uc6 -> Edit employee
        public ActionResult Edit(EmployeeViewModel item)
        {
            RegisterEmpRequestModel emp = new RegisterEmpRequestModel
            {
                EmpId       = item.EmpId,
                Name        = item.Name,
                Gender      = item.Gender,
                Department  = item.Department,
                SalaryId    = item.SalaryId.ToString(),
                StartDate   = item.StartDate,
                Description = item.Description
            };

            return(View(emp));
        }
Exemple #9
0
        public ActionResult RegisterEmployee(RegisterEmpRequestModel employee)
        {
            bool result = false;

            if (ModelState.IsValid)
            {
                result = this.empService.RegisterEmployee(employee);
            }
            ModelState.Clear();

            if (result == true)
            {
                return(RedirectToAction("EmployeeList"));
            }
            return(View("Register", employee));
        }
Exemple #10
0
 public bool EditEmployee(RegisterEmpRequestModel employee)
 {
     try
     {
         Employee validEmp = db.Employees.Where(x => x.EmpId == employee.EmpId).FirstOrDefault();
         if (validEmp != null)
         {
             int departmentId = db.Departments.Where(x => x.DeptName == employee.Department).Select(x => x.DeptId).FirstOrDefault();
             validEmp.EmpId        = employee.EmpId;
             validEmp.Name         = employee.Name;
             validEmp.Gender       = employee.Gender;
             validEmp.DepartmentId = departmentId;
             validEmp.SalaryId     = Convert.ToInt32(employee.SalaryId);
             validEmp.StartDate    = employee.StartDate;
             validEmp.Description  = employee.Description;
             //Employee UpdatedEmp = new Employee()
             //{
             //    EmpId = employee.EmpId,
             //    Name = employee.Name,
             //    Gender = employee.Gender,
             //    DepartmentId = employee.DepartmentId,
             //    SalaryId = employee.SalaryId,
             //    StartDate = employee.StartDate,
             //    Description = employee.Description
             //};
             //db.Entry<Employee>(UpdatedEmp).State = System.Data.Entity.EntityState.Modified;
             int result = db.SaveChanges();
             if (result > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         return(false);
     }
     catch (Exception e)
     {
         throw e;
     }
 }