Пример #1
0
        public bool AddEmployee(Employee toAdd, Employee currentAdmin)
        {
            bool result = currentAdmin != null &&
                          _model.Employees.FirstOrDefault(x =>
                                                          x.Id == currentAdmin.Id && x.Login == currentAdmin.Login) != null && _model.Employees.FirstOrDefault(x => x.Login == toAdd.Login) == null;

            if (result)
            {
                try
                {
                    _model.Employees.Add(toAdd);
                    var change = new EmployeeChange(currentAdmin, toAdd, "User created");
                    _model.EmployeesChanges.Add(change);
                    _model.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    _model.Entry(_model.Employees).CurrentValues.SetValues(_model.Entry(_model.Employees).OriginalValues);
                    _model.Entry(_model.EmployeesChanges).CurrentValues.SetValues(_model.Entry(_model.EmployeesChanges).OriginalValues);
                    throw;
                }
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
 public EmployeeChange(EmployeeChange toCopy)
 {
     Id          = toCopy.Id;
     Date        = toCopy.Date;
     Details     = toCopy.Details;
     Changing_Id = toCopy.Changing_Id;
     Changed_Id  = toCopy.Changed_Id;
     Employee1   = toCopy.Employee1;
     Employee    = toCopy.Employee;
 }