Exemple #1
0
        public List <ModelEmployee> GetListOfEmployeesByDepartment(int departmentId)
        {
            List <ModelEmployee> myListOfEmployees = new List <ModelEmployee>();

            RepositoryManager.ExecuteSqlCommand((command) =>
            {
                command.CommandText = @"select * from Employee 
                                        where DepartmentId = @DepartmentId ";
                command.Parameters.Add("@DepartmentId", SqlDbType.Int).Value = departmentId;

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ModelEmployee employee = new ModelEmployee
                        {
                            Id           = reader.GetInt32(0),
                            Title        = reader.IsDBNull(1) ? "" : reader.GetString(1),
                            Name         = reader.GetString(2),
                            Surname      = reader.GetString(3),
                            PhoneNumber  = reader.IsDBNull(4) ? "" : reader.GetString(4),
                            Email        = reader.GetString(5),
                            DepartmentId = reader.IsDBNull(6) ? null : (int?)reader.GetInt32(6)
                        };
                        myListOfEmployees.Add(employee);
                    }
                }
            });
            return(myListOfEmployees);
        }
Exemple #2
0
        public bool UpdateEmployee(ModelEmployee employee)
        {
            bool isSuccessful = false;

            RepositoryManager.ExecuteSqlCommand((command) =>
            {
                command.CommandText = @"update Employee
                                            set Name=@Name,Surname=@Surname,Title=@Title,
                                                PhoneNumber=@PhoneNumber,Mail=@Email,DepartmentId=@DepartmentID
                                            where id =@Id";

                command.Parameters.Add("@DepartmentID", SqlDbType.Int).Value     = employee.DepartmentId ?? (Object)DBNull.Value;
                command.Parameters.Add("@Title", SqlDbType.NVarChar).Value       = employee.Title;
                command.Parameters.Add("@Name", SqlDbType.NVarChar).Value        = employee.Name;
                command.Parameters.Add("@Surname", SqlDbType.NVarChar).Value     = employee.Surname;
                command.Parameters.Add("@PhoneNumber", SqlDbType.NVarChar).Value = employee.PhoneNumber;
                command.Parameters.Add("@Email", SqlDbType.NVarChar).Value       = employee.Email;
                command.Parameters.Add("@Id", SqlDbType.Int).Value = employee.Id;

                if (command.ExecuteNonQuery() > 0)
                {
                    isSuccessful = true;
                }
            });

            return(isSuccessful);
        }
Exemple #3
0
        public List <ModelEmployee> GetListOfEmployees()
        {
            List <ModelEmployee> myListOfEmployees = new List <ModelEmployee>();

            RepositoryManager.ExecuteSqlCommand((command) =>
            {
                command.CommandText = @"select e.* 
                                        from Employee as e
                                        left join Department as d on e.DepartmentId=d.Id 
                                        where e.DepartmentId is null or not (e.DepartmentId = d.Id and d.DepartmentType='Company') ";
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ModelEmployee employee = new ModelEmployee
                        {
                            Id           = reader.GetInt32(0),
                            Title        = reader.IsDBNull(1) ? "" : reader.GetString(1),
                            Name         = reader.GetString(2),
                            Surname      = reader.GetString(3),
                            PhoneNumber  = reader.IsDBNull(4) ? "" : reader.GetString(4),
                            Email        = reader.GetString(5),
                            DepartmentId = reader.IsDBNull(6) ? null : (int?)reader.GetInt32(6)
                        };
                        myListOfEmployees.Add(employee);
                    }
                }
            });
            return(myListOfEmployees);
        }
Exemple #4
0
        public ModelEmployee GetEmployee(int employeeId)
        {
            ModelEmployee employee = new ModelEmployee();

            RepositoryManager.ExecuteSqlCommand((command) =>
            {
                command.CommandText = @"select * 
                                            from Employee as e 
                                            where e.ID = @Id";

                command.Parameters.Add("@Id", SqlDbType.Int).Value = employeeId;

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        employee.Id           = reader.GetInt32(0);
                        employee.Title        = reader.IsDBNull(1) ? "" : reader.GetString(1);
                        employee.Name         = reader.GetString(2);
                        employee.Surname      = reader.GetString(3);
                        employee.PhoneNumber  = reader.IsDBNull(4) ? "" : reader.GetString(4);
                        employee.Email        = reader.GetString(5);
                        employee.DepartmentId = reader.IsDBNull(6) ? null : (int?)reader.GetInt32(6);
                    }
                }
            });
            return(employee);
        }
        public IHttpActionResult Put(int id, ModelEmployee model)
        {
            try
            {
                var emp = _unitOfWork.Employees.GetById(id);
                if (emp == null)
                {
                    return(NotFound());
                }

                //(Source,Destination)
                _mapper.Map(model, emp);

                if (_unitOfWork.Complete() > 0)
                {
                    AppLogger.Info("Update employee successful. From: Employees using Web API");
                    return(Ok(_mapper.Map <ModelEmployee>(emp)));
                }
                else
                {
                    AppLogger.Error("Update employee error. From: Employees using Web API");
                    return(InternalServerError());
                }
            }
            catch (Exception ex)
            {
                AppLogger.Error("Update employee error. From: Employees using Web API");
                return(InternalServerError(ex));
            }
        }
Exemple #6
0
 public FrmCreateEditEmployee(ModelEmployee employee)
 {
     InitializeComponent();
     _employee = employee;
     _isCreate = false;
     FillTxtBoxes();
 }
Exemple #7
0
        public bool CreateEmployee(ModelEmployee employee)
        {
            bool isSuccessful = false;

            RepositoryManager.ExecuteSqlCommand((command) =>
            {
                command.CommandText = @"insert into [dbo].[Employee]
                        values (@Title,@Name,@Surname,@PhoneNumber,@Mail,@DepartmentID)";

                command.Parameters.Add("@DepartmentID", SqlDbType.Int).Value     = employee.DepartmentId ?? (Object)DBNull.Value;
                command.Parameters.Add("@Title", SqlDbType.NVarChar).Value       = employee.Title;
                command.Parameters.Add("@Name", SqlDbType.NVarChar).Value        = employee.Name;
                command.Parameters.Add("@Surname", SqlDbType.NVarChar).Value     = employee.Surname;
                command.Parameters.Add("@PhoneNumber", SqlDbType.NVarChar).Value = employee.PhoneNumber;
                command.Parameters.Add("@Mail", SqlDbType.NVarChar).Value        = employee.Email;


                if (command.ExecuteNonQuery() > 0)
                {
                    isSuccessful = true;
                }
            });

            return(isSuccessful);
        }
        public ModelEmployee GetEmployee(int id)
        {
            Employees     employee      = repo.Find(x => x.EmployeeID == id);
            ModelEmployee modelemployee = new ModelEmployee
            {
                EmployeeID = employee.EmployeeID,

                Extension = employee.Extension,
                Address   = employee.Address,
                City      = employee.City,
                FirstName = employee.FirstName,

                HomePhone  = employee.HomePhone,
                Region     = employee.Region,
                PostalCode = employee.PostalCode,
                Country    = employee.Country,
                LastName   = employee.LastName,

                Title           = employee.Title,
                TitleOfCourtesy = employee.TitleOfCourtesy,
                ReportsTo       = employee.ReportsTo
            };

            return(modelemployee);
        }
Exemple #9
0
 public ActionResult AddOrEdit(int?id)
 {
     if (id == null)
     {
         using (DBModel db = new DBModel())
         {
             ViewBag.Country = new SelectList(db.Countries.ToList(), "CountryId", "CountryName");
         }
         return(View());
     }
     else
     {
         using (DBModel db = new DBModel())
         {
             ModelEmployee emp = new ModelEmployee();
             ViewBag.Country = new SelectList(db.Countries.ToList(), "CountryId", "CountryName");
             emp             = db.Employees.Where(x => x.EmployeeId == id).Select(x => new ModelEmployee
             {
                 EmployeeId = x.EmployeeId,
                 Name       = x.Name,
                 Position   = x.Position,
                 Office     = x.Office,
                 Age        = x.Age,
                 Salary     = x.Salary,
                 CountryId  = x.CountryId,
                 StateId    = x.StateId,
                 CityId     = x.CityId
             }).FirstOrDefault();
             return(View(emp));
         }
     }
 }
Exemple #10
0
        private void Button1_Click(object sender, EventArgs e)
        {
            FrmEmployeesManager employeesOverView = new FrmEmployeesManager();

            if (_department != null)
            {
                _createEditDepartmentViewModel.SetDepartmentForEmployee((int)_department.ManagerEmployeeId, null);
                lblBossName.Text = "";
            }
            employeesOverView.ShowDialog();

            if (employeesOverView.DialogResult == DialogResult.OK)
            {
                _bossId = employeesOverView.SelectedId;

                if (_department != null)
                {
                    _department.ManagerEmployeeId = _bossId;
                }

                ModelEmployee boss = _createEditDepartmentViewModel.GetEmployee(_bossId);
                lblBossName.Text   = $"{_departmentType.ToString()} Boss Name: {boss.Title} {boss.Name} {boss.Surname}";
                btnConfirm.Enabled = true;
            }
        }
Exemple #11
0
        public ActionResult AllIncident()
        {
            var           NumberIncident = Request["searchIncident"];
            String        serialNumber   = TempData["Employee"].ToString();
            ModelEmployee employee       = new ModelEmployee().SearchEmployeeByNumber(serialNumber);

            if (employee.IsTecnic == 1)
            {
                if (NumberIncident != null && NumberIncident != "")
                {
                    ViewBag.ModelIncidents = new ModelIncidents().SearchIncident(NumberIncident);
                }
                else
                {
                    ViewBag.ModelIncidents = new ModelIncidents().ListIncident();
                }
            }
            else
            {
                if (NumberIncident != null && NumberIncident != "")
                {
                    ViewBag.ModelIncidents = new ModelIncidents().SearchIncident(NumberIncident, employee.SeriaNumber);
                }
                else
                {
                    ViewBag.ModelIncidents = new ModelIncidents().ListIncident(employee.SeriaNumber);
                }
            }
            TempData["Employee"] = serialNumber;
            return(View());
        }
        public List <ModelEmployee> GetEmployeeList()
        {
            List <Employees>     employeelist      = repo.List();
            List <ModelEmployee> modelemployeelist = new List <ModelEmployee>();

            foreach (var employee in employeelist)
            {
                ModelEmployee modelemployee = new ModelEmployee
                {
                    EmployeeID = employee.EmployeeID,
                    Extension  = employee.Extension,
                    Address    = employee.Address,
                    City       = employee.City,
                    FirstName  = employee.FirstName,
                    HomePhone  = employee.HomePhone,
                    Region     = employee.Region,
                    PostalCode = employee.PostalCode,
                    Country    = employee.Country,
                    LastName   = employee.LastName,

                    Title           = employee.Title,
                    TitleOfCourtesy = employee.TitleOfCourtesy,
                    ReportsTo       = employee.ReportsTo
                };
                modelemployeelist.Add(modelemployee);
            }
            return(modelemployeelist);
        }
        //Метод для поиска сотрудника в БД
        private IQueryable <Employee> FoundEmployee(ModelEmployee sel, DbSet <Employee> employees)
        {
            var found = from emp in employees
                        where emp.SecondName == sel.SecondName && emp.FirstName == sel.FirstName
                        select emp;

            return(found);
        }
Exemple #14
0
 private void FillTxtBoxes()
 {
     txtBoxCode.Text = _department.Code;
     txtBoxName.Text = _department.Name;
     if (_department.ManagerEmployeeId != null)
     {
         ModelEmployee boss = _createEditDepartmentViewModel.GetEmployee((int)_department.ManagerEmployeeId);
         lblBossName.Text = $"{_department.DepartmentType.ToString()} Boss Name: {boss.Title} {boss.Name} {boss.Surname}";
     }
 }
Exemple #15
0
 public frmAddEmployee(ModelEmployee modelEmployee)
 {
     InitializeComponent();
     _modelEmployee    = modelEmployee;
     txtTitle.Text     = _modelEmployee.Title;
     txtFirstName.Text = _modelEmployee.FirstName;
     txtLastName.Text  = _modelEmployee.LastName;
     txtPhone.Text     = _modelEmployee.Phone;
     txtEmail.Text     = _modelEmployee.Email;
 }
Exemple #16
0
        public ActionResult Save()
        {
            ModelEmployee employee = new ModelEmployee();

            employee.Name        = Request["Name"];
            employee.Departament = Request["Departament"];
            employee.SeriaNumber = Request["SerialNumber"];
            employee.IsTecnic    = Convert.ToInt32(Request["IsTecnic"]);
            employee.Password    = Request["Password"];

            employee.SaveEmployee();

            return(RedirectToAction("CreateEmployee"));
        }
Exemple #17
0
        public bool CreateEmployee(string title, string name, string surname, string phoneNumber, string email, int?departmentId)
        {
            ModelEmployee employee = new ModelEmployee
            {
                Title        = title,
                Name         = name,
                Surname      = surname,
                PhoneNumber  = phoneNumber,
                Email        = email,
                DepartmentId = departmentId
            };

            return(RepositoryManager.RepositoryEmployee.CreateEmployee(employee));
        }
Exemple #18
0
        public object AlterEmployee()
        {
            ModelEmployee employee = new ModelEmployee();

            employee.Name        = Request["Name"];
            employee.Departament = Request["Departament"];
            employee.SeriaNumber = Request["SerialNumber"];
            employee.IsTecnic    = Convert.ToInt32(Request["IsTecnic"]);
            employee.Password    = Request["Password"];

            employee.AlterEmployeetByNumber();

            return(RedirectToAction("AllEmployee"));
        }
        private void btnAddEmployy_Click(object sender, EventArgs e)
        {
            frmEmployee employee = new frmEmployee();

            if (employee.ShowDialog() == DialogResult.OK)
            {
                _sectionDirectorId = employee.DirectorId;
            }
            ModelEmployee employeeModel = new ModelEmployee();

            employeeModel = _sectionManagerViewModel.SelectEmployeeById(_sectionDirectorId);
            employeeModel.WorkAtDepartmentId = Convert.ToInt32(dgwDepartment.SelectedRows[0].Cells[0].Value);
            _sectionManagerViewModel.UpdateEmployee(employeeModel);
            dgwDepartment_SelectionChanged(this, new EventArgs());
        }
        public bool UpdateEmployeeWorkAt(ModelEmployee modelEmployee)
        {
            bool success = false;

            Execute((command) =>
            {
                command.CommandText = "update employee set WorkAtID= @WorkAt where id=@idEmployee";
                command.Parameters.Add("@WorkAt", SqlDbType.Int).Value     = modelEmployee.WorkAtDepartmentId;
                command.Parameters.Add("@idEmployee", SqlDbType.Int).Value = modelEmployee.Id;
                if (command.ExecuteNonQuery() > 0)
                {
                    success = true;
                }
            });
            return(success);
        }
Exemple #21
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            ModelEmployee modelEmployee = new ModelEmployee();

            modelEmployee.Id        = Convert.ToInt32(dgwEmployee.SelectedRows[0].Cells[0].Value);
            modelEmployee.Title     = (dgwEmployee.SelectedRows[0].Cells[1].Value).ToString();
            modelEmployee.FirstName = (dgwEmployee.SelectedRows[0].Cells[2].Value).ToString();
            modelEmployee.LastName  = (dgwEmployee.SelectedRows[0].Cells[3].Value).ToString();
            modelEmployee.Phone     = (dgwEmployee.SelectedRows[0].Cells[4].Value).ToString();
            modelEmployee.Email     = (dgwEmployee.SelectedRows[0].Cells[5].Value).ToString();
            frmAddEmployee addEmployee = new frmAddEmployee(modelEmployee);

            if (addEmployee.ShowDialog() == DialogResult.OK)
            {
                FillGrid();
            }
        }
Exemple #22
0
 public ActionResult AddOrEdit(ModelEmployee memp)
 {
     try
     {
         using (DBModel db = new DBModel())
         {
             Employee emp = new Employee();
             if (memp.EmployeeId == 0)
             {
                 emp.Name      = memp.Name;
                 emp.Position  = memp.Position;
                 emp.Office    = memp.Office;
                 emp.Age       = memp.Age;
                 emp.Salary    = memp.Salary;
                 emp.CountryId = memp.CountryId;
                 emp.StateId   = memp.StateId;
                 emp.CityId    = memp.CityId;
                 db.Employees.Add(emp);
                 db.SaveChanges();
                 return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 var empp = db.Employees.Find(memp.EmployeeId);
                 empp.Name      = memp.Name;
                 empp.Position  = memp.Position;
                 empp.Office    = memp.Office;
                 empp.Age       = memp.Age;
                 empp.Salary    = memp.Salary;
                 empp.CountryId = memp.CountryId;
                 empp.StateId   = memp.StateId;
                 empp.CityId    = memp.CityId;
                 db.SaveChanges();
                 return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public bool InsertEmployee(ModelEmployee modelEmployee)
        {
            bool success = false;

            Execute((command) =>
            {
                command.CommandText = @"Insert into employee ([Title], [FirstName], [LastName], [Phone], [Email])
                                    Values(@Title, @First, @Last, @Phone, @Email)";
                command.Parameters.Add("@Title", SqlDbType.VarChar).Value = modelEmployee.Title;
                command.Parameters.Add("@First", SqlDbType.VarChar).Value = modelEmployee.FirstName;
                command.Parameters.Add("@Last", SqlDbType.VarChar).Value  = modelEmployee.LastName;
                command.Parameters.Add("@Phone", SqlDbType.VarChar).Value = modelEmployee.Phone;
                command.Parameters.Add("@Email", SqlDbType.VarChar).Value = modelEmployee.Email;
                if (command.ExecuteNonQuery() > 0)
                {
                    success = true;
                }
            });
            return(success);
        }
Exemple #24
0
        // GET: Employee
        public ActionResult Login()
        {
            var SerialNumber = Request["SerialNumber"];
            var Password     = Request["Password"];

            ModelEmployee employee = new ModelEmployee();

            employee = new ModelEmployee().Login(SerialNumber, Password);
            if (employee.Name != null)
            {
                TempData["Employee"] = employee.SeriaNumber;
                return(RedirectToAction("Index", "StartView"));
            }
            else
            {
                TempData["Erro"]    = true;
                TempData["Message"] = "Login não possui perfil no sistema!";

                return(View());
            }
        }
 public AddLetterViewModel()
 {
     CatalogueBD = new CatalogueDBContext();
     Employees   = new ObservableCollection <ModelEmployee>();
     //Заполнение списка сотрудников из базы
     foreach (Employee emp in CatalogueBD.Employees.Include(x => x.Letters).ToList())
     {
         Employees.Add(new ModelEmployee()
         {
             FirstName  = emp.FirstName,
             SecondName = emp.SecondName,
             FullName   = emp.FirstName + " " + emp.SecondName
         });
     }
     if (Employees.Count > 0) //Назначаем начальные значения для combobox
     {
         selectedSender    = Employees[0];
         selectedRecipient = Employees[0];
     }
     inputDateTime = DateTime.Now;
 }
        public bool UpdateEmployee(ModelEmployee modelEmployee)
        {
            bool success = false;

            Execute((command) =>
            {
                command.CommandText = @"Update employee set [Title] = @Title, [FirstName] = @FirstName, [LastName] = @LastName, 
                                             [Phone] = @Phone, [Email] = @Email, [WorkAtID]=@WorkAt where id=@id";
                command.Parameters.Add("@id", SqlDbType.Int).Value            = modelEmployee.Id;
                command.Parameters.Add("@Title", SqlDbType.VarChar).Value     = modelEmployee.Title;
                command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = modelEmployee.FirstName;
                command.Parameters.Add("@LastName", SqlDbType.VarChar).Value  = modelEmployee.LastName;
                command.Parameters.Add("@Phone", SqlDbType.VarChar).Value     = modelEmployee.Phone;
                command.Parameters.Add("@Email", SqlDbType.VarChar).Value     = modelEmployee.Email;
                command.Parameters.Add("@WorkAt", SqlDbType.Int).Value        = modelEmployee.WorkAtDepartmentId;
                if (command.ExecuteNonQuery() > 0)
                {
                    success = true;
                }
            });
            return(success);
        }
        public ModelEmployee SelectEmployeeById(int employeeId)
        {
            ModelEmployee modelEmployee = new ModelEmployee();

            Execute((command) =>
            {
                command.CommandText = "select [Title], [FirstName], [LastName], [Phone], [Email], [id] " +
                                      " from employee where id=@employeeId";
                command.Parameters.Add("@employeeId", SqlDbType.Int).Value = employeeId;
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        modelEmployee.Title     = reader.GetString(0);
                        modelEmployee.FirstName = reader.GetString(1);
                        modelEmployee.LastName  = reader.GetString(2);
                        modelEmployee.Phone     = reader.GetString(3);
                        modelEmployee.Email     = reader.GetString(4);
                        modelEmployee.Id        = reader.GetInt32(5);
                    }
                }
            });
            return(modelEmployee);
        }
        public IHttpActionResult Post(ModelEmployee model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_unitOfWork.Employees.GetById(model.Id) != null)
                    {
                        AppLogger.Debug("New employee unsuccessfull. From: Employees using Web API");
                        ModelState.AddModelError("ID", "Id is in use");
                    }
                    else
                    {
                        //<Destination>(Source)
                        var emp = _mapper.Map <Employee>(model);
                        _unitOfWork.Employees.Add(emp);

                        if (_unitOfWork.Complete() > 0)
                        {
                            var newModel = _mapper.Map <ModelEmployee>(emp);
                            //CreatedAtRoute("GetEmployee", new { moniker = newModel.Id }, newModel);
                            AppLogger.Info("New employee successfull. From: Employees using Web API");
                            return(Ok(newModel));
                        }
                        ;
                    }
                }
            }
            catch (Exception ex)
            {
                AppLogger.Error("New employee error. From: Employees using Web API");
                return(InternalServerError(ex));
            }
            AppLogger.Debug("New employee unsuccessfull. From: Employees using Web API");
            return(BadRequest(ModelState));
        }
Exemple #29
0
 private void btnSaveDirector_Click(object sender, EventArgs e)
 {
     if (_modelEmployee == null)
     {
         ModelEmployee model = new ModelEmployee();
         model.Title     = txtTitle.Text;
         model.FirstName = txtFirstName.Text;
         model.LastName  = txtLastName.Text;
         model.Phone     = txtPhone.Text;
         model.Email     = txtEmail.Text;
         _addEmployeeViewModel.InsertEmployee(model);
     }
     else
     {
         _modelEmployee.Title     = txtTitle.Text;
         _modelEmployee.FirstName = txtFirstName.Text;
         _modelEmployee.LastName  = txtLastName.Text;
         _modelEmployee.Phone     = txtPhone.Text;
         _modelEmployee.Email     = txtEmail.Text;
         _addEmployeeViewModel.UpdateEmployeeBy(_modelEmployee);
     }
     DialogResult = DialogResult.OK;
     Close();
 }
Exemple #30
0
        public ManForm()
        {
            InitializeComponent();

            m_model = new ModelEmployee();
        }