//public void  Delete(AddEmployee criteria)
        //{
        //    var deleted =  _ctx.Employees
        //                        .Include(e => e.Dependents)
        //                        .First(e => e.Id == criteria.Id);
        //    _ctx.Remove(deleted);
        //    _ctx.SaveChangesAsync();
        //}

        public int Add(AddEmployee emp)
        {
            try
            {
                _logger.LogInformation("Add new Employee");
                var result = new Entities.Employee
                {
                    FirstName  = emp.Employee.FirstName,
                    LastName   = emp.Employee.LastName,
                    Dependents = emp.Dependents.Select(ed => new Entities.Info
                    {
                        FirstName = ed.FirstName,
                        LastName  = ed.LastName
                    }).ToList()
                };
                _ctx.Add(result);
                _ctx.SaveChanges();
                return(result.Id);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to add employee: {ex}");
                return(0);
            }
        }
Esempio n. 2
0
        static void GenerateEmployees()
        {
            var connectionString = TestTaskConfiguration.Instance.ConnectionString;
            var context = new DataContext(connectionString);
            var repository = new EmployeeRepository(context);
            var service = new EmployeeService(repository);

            var wageRandom = new Random();
            var positionRandom = new Random();

            for (var i = 0; i < 100; i++)
            {
                var employee = new Employee
                {
                    FirstName = GenerateAnRandomString(),
                    Wage = wageRandom.Next(100, 100000),
                    Position = GenerateAnRandomString(),
                    Status = (EmployeeStatus)positionRandom.Next(1, 2),
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow
                };

                service.Create(employee);

                Console.WriteLine($"{i} employee was added into DB");
            }
        }
Esempio n. 3
0
 public virtual void AddEmployee(Employee employee)
 {
     employee.Store = this;
     Staff.Add(employee);
 }
        public void Update(Employee item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(Employee));
            }

            _employeeRepository.Update(item);
        }