public ActionResult Create(Employee employee)
        {
            var employeeList = db.Employees.ToList();
            int newId = employeeList.Last().id + 1;

            employee.id = newId;

            if (employee.name == null || employee.email == null)
            {
                ViewBag.empId = newId;

                return View("Create", employee);
            }
            else{

            }

            db.Employees.Add(employee);
            db.SaveChanges();
            return RedirectToAction("Index");
            
        }
 /// <summary>
 /// Method for deleting employee from database
 /// </summary>
 /// <param name="employeeID"></param>
 public void DeleteEmployee(tblEmployee employee)
 {
     try
     {
         using (EmployeeManagementEntities context = new EmployeeManagementEntities())
         {
             if (LogInService.IsManager(employee))
             {
                 tblManager managerToDelete = (from m in context.tblManagers where m.EmployeeId == employee.EmployeeId select m).First();
                 context.tblManagers.Remove(managerToDelete);
                 context.SaveChanges();
             }
             tblEmployee employeeToDelete = (from e in context.tblEmployees where e.EmployeeId == employee.EmployeeId select e).First();
             context.tblEmployees.Remove(employeeToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Beispiel #3
0
        public EmployeeContract AddEmployee(EmployeeContract employeeContract)
        {
            EmployeeDetail employee = new EmployeeDetail()
            {
                Name   = employeeContract.Name,
                Email  = employeeContract.Email,
                Salary = employeeContract.Salary
            };

            employeeManagementEntitiesObj.EmployeeDetails.Add(employee);
            employeeManagementEntitiesObj.SaveChanges();
            employeeContract.Id = employee.id;
            return(employeeContract);
        }
Beispiel #4
0
 public DepartmentModel AddAndUpdateDepartment(DepartmentModel model)
 {
     try
     {
         if (model.ID > 0)
         {
             var record = _db.tblDepartments.OrderByDescending(x => x.ID).Where(x => x.ID == model.ID).FirstOrDefault();
             record.Name = model.Name;
             _db.SaveChanges();
         }
         else
         {
             tblDepartment _department = new tblDepartment();
             _department.Name = model.Name;
             _db.tblDepartments.Add(_department);
             _db.SaveChanges();
             model.ID = _department.ID;
         }
     }
     catch (Exception ex)
     {
     }
     return(model);
 }
Beispiel #5
0
 public EmployeeModel AddAndUpdateEmployee(EmployeeModel model)
 {
     try
     {
         if (model.ID > 0)
         {
             var record = _db.tblEmployees.OrderByDescending(x => x.ID).Where(x => x.ID == model.ID).FirstOrDefault();
             record.tblJobID      = model.tblJobID;
             record.tblDepartment = model.tblDepartment;
             record.Name          = model.Name;
             record.PhoneNumber   = model.PhoneNumber;
             record.Salary        = model.Salary;
             record.Email         = model.Email;
             record.HireDate      = model.HireDate;
             _db.SaveChanges();
         }
         else
         {
             tblEmployee _Employee = new tblEmployee();
             _Employee.tblJobID      = model.tblJobID;
             _Employee.tblDepartment = model.tblDepartment;
             _Employee.Name          = model.Name;
             _Employee.PhoneNumber   = model.PhoneNumber;
             _Employee.Salary        = model.Salary;
             _Employee.Email         = model.Email;
             _Employee.HireDate      = model.HireDate;
             _db.tblEmployees.Add(_Employee);
             _db.SaveChanges();
             model.ID = _Employee.ID;
         }
     }
     catch (Exception ex)
     {
     }
     return(model);
 }
 /// <summary>
 /// Method for deleting reports from database
 /// </summary>
 /// <param name="reportID"></param>
 public void DeleteReport(int reportID)
 {
     try
     {
         using (EmployeeManagementEntities context = new EmployeeManagementEntities())
         {
             tblReport reportToDelete = (from r in context.tblReports where r.ReportId == reportID select r).First();
             context.tblReports.Remove(reportToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Beispiel #7
0
 /// <summary>
 /// Updates the specified employee.
 /// </summary>
 /// <param name="employee">The employee.</param>
 /// <returns></returns>
 public int Update(Employee employee)
 {
     try
     {
         using (EmployeeManagementEntities db = new EmployeeManagementEntities())
         {
             db.Entry(employee).State = System.Data.Entity.EntityState.Modified;
             return(db.SaveChanges());
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         return(0);
     }
 }
Beispiel #8
0
 /// <summary>
 /// Inserts the specified employee.
 /// </summary>
 /// <param name="employee">The employee.</param>
 /// <returns></returns>
 public int Insert(Employee employee)
 {
     using (EmployeeManagementEntities db = new EmployeeManagementEntities())
     {
         try
         {
             var employees = db.Employees;
             employees.Add(employee);
             return(db.SaveChanges());
         }
         catch (Exception exception)
         {
             Console.WriteLine(exception.Message);
             return(0);
         }
     }
 }
Beispiel #9
0
        /// <summary>
        /// Deletes the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public int Delete(int id)
        {
            try
            {
                using (EmployeeManagementEntities db = new EmployeeManagementEntities())
                {
                    Employee employee = new Employee();
                    employee = db.Employees.SingleOrDefault(s => s.ID == id);
                    if (employee != null)
                    {
                        db.Employees.Remove(employee);
                    }

                    return(db.SaveChanges());
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return(0);
            }
        }
        /// <summary>
        /// Method for adding or editing reports into database by Employee
        /// </summary>
        /// <param name="report"></param>
        /// <returns></returns>
        public string AddReport(vwReport report)
        {
            try
            {
                using (EmployeeManagementEntities context = new EmployeeManagementEntities())
                {
                    if (report.ReportId == 0)
                    {
                        int noOfreports = (from x in context.tblReports where x.EmployeeId == report.EmployeeId && x.ReportDate == report.ReportDate select x).Count();
                        if (noOfreports < 2)
                        {
                            int hours = 0;
                            if (noOfreports == 1)
                            {
                                hours = (from x in context.tblReports where x.EmployeeId == report.EmployeeId && x.ReportDate == report.ReportDate select x.WorkHours).FirstOrDefault();
                            }

                            if (hours + report.WorkHours <= 12)
                            {
                                tblReport newReport = new tblReport();
                                newReport.EmployeeId = report.EmployeeId;
                                newReport.ReportDate = report.ReportDate;
                                newReport.Project    = report.Project;
                                newReport.WorkHours  = report.WorkHours;
                                context.tblReports.Add(newReport);
                                context.SaveChanges();
                                return(null);
                            }
                        }
                    }

                    else
                    {
                        tblReport reportToEdit = (from x in context.tblReports where x.ReportId == report.ReportId select x).FirstOrDefault();
                        reportToEdit.ReportDate = report.ReportDate;
                        reportToEdit.Project    = report.Project;
                        reportToEdit.WorkHours  = report.WorkHours;
                        int rep = (from x in context.tblReports where x.EmployeeId == report.EmployeeId && x.ReportDate == report.ReportDate && x.ReportId != report.ReportId select x.WorkHours).FirstOrDefault();
                        if (rep == 0 && reportToEdit.WorkHours <= 12)
                        {
                            context.SaveChanges();
                            return(null);
                        }
                        else if (rep + reportToEdit.WorkHours <= 12)
                        {
                            context.SaveChanges();
                        }
                        else
                        {
                            return("Cannot have more than 12 work hours.");
                        }
                    }
                }
                return("Cannot have more than 12 work hours.");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }