Beispiel #1
0
        private void Save(object sender, EventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }

            // Removing relations
            if (_selectedEmployee != null)
            {
                foreach (var project in _projectsRepository.GetAll())
                {
                    foreach (var relation in project.EmployeesList)
                    {
                        if (_selectedEmployee.Equals(relation.Employee))
                        {
                            project.EmployeesList.Remove(relation);
                            break;
                        }
                    }
                }

                _employeesRepository.Remove(_selectedEmployee);
            }

            // Adding new employee
            var projectsList = addedProjectsListBox.Items.Cast <Relation>().ToList();

            var employeeToAdd = new Employee(employeeFirstName.Text.NameFormatting(),
                                             employeeLastName.Text.NameFormatting(), employeeOib.Text, Convert.ToDateTime(employeeBirthday.Text),
                                             (Role)employeeRole.SelectedItem);

            _employeesRepository.Add(employeeToAdd);

            var addedEmployee = _employeesRepository.GetAll().Find(x => x.Oib == employeeToAdd.Oib);

            // Adding projects to Employee.ProjectsList
            foreach (var relationProject in projectsList)
            {
                addedEmployee.ProjectsList.Add(relationProject);
            }

            // Adding employee to relational projects
            foreach (var project in _projectsRepository.GetAll())
            {
                foreach (var relation in projectsList)
                {
                    if (relation.Project.Equals(project))
                    {
                        project.EmployeesList.Add(new Relation(addedEmployee, relation.WeeklyWorkHours));
                        break;
                    }
                }
            }

            Close();
        }
        private async Task <Employee> CreateEmployee()
        {
            var employeeRepository = new EmployeesRepository(GetContext());
            var employyeModel      = new Employee(Guid.NewGuid(), "Sedat", "Kocaer", "Sales Representative", DateTime.Parse("1.05.1992 00:00:00"),
                                                  DateTime.Parse("1.05.1992 00:00:00"), "507 - 20th Ave. E.Apt. 2A", "Istanbul", "34000", "Turkiye");

            await employeeRepository.Add(employyeModel);

            await employeeRepository.UnitOfWork.Commit();

            return(employyeModel);
        }
Beispiel #3
0
        public ActionResult <Employee> Post([FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                _employeesRepository.Add(employee);
                _employeesRepository.SaveChanges();
            }
            catch (Exception ex)
            {
                return(BadRequest(_translationService.TranslateException(ex, Request.Headers)));
            }

            return(Ok(employee));
        }
Beispiel #4
0
        public async Task Add_Test()
        {
            var target = new EmployeesRepository(this.dataContext);

            var newEmp = new EmployeeModel
            {
                FirstName = "New", LastName = "Employee", Birth = DateTime.Now.AddYears(-10), Salary = 10000, TaxNumber = "0987", WorkingPosition = "Junior Dev"
            };

            target.Add(newEmp);

            await target.Save();

            Assert.AreEqual(3, newEmp.Id);
            Assert.IsTrue(await this.dataContext.Employees.AnyAsync(x => x.Id == newEmp.Id));
            Assert.IsTrue(await this.dataContext.Employees.AnyAsync(x => x.LastName == newEmp.LastName));
            Assert.IsTrue(await this.dataContext.Employees.AnyAsync(x => x.FirstName == newEmp.FirstName));
            Assert.IsTrue(await this.dataContext.Employees.AnyAsync(x => x.Birth == newEmp.Birth));
            Assert.IsTrue(await this.dataContext.Employees.AnyAsync(x => x.Salary == newEmp.Salary));
            Assert.IsTrue(await this.dataContext.Employees.AnyAsync(x => x.TaxNumber == newEmp.TaxNumber));
            Assert.IsTrue(await this.dataContext.Employees.AnyAsync(x => x.WorkingPosition == newEmp.WorkingPosition));
        }
        public Person Create([FromBody] Person employee)
        {
            repository.Add(employee);

            return(employee);
        }
 public void Add(EmployeeModel employee)
 {
     _employeesRepository.Add(employee.ToEntity());
 }