public IEnumerable <EmployeeVM> GetAll() { ObservableCollection <EmployeeVM> res = new ObservableCollection <EmployeeVM>(); using (var unitOf = new UnitOfWork()) { var emplList = unitOf.employeeRepository.GetList(); var depEmplList = unitOf.departmentEmployeeRepository.GetList(); foreach (var emp in emplList) { var tempDE = depEmplList.FirstOrDefault(de => de.employeeId == emp.employeeId); if (tempDE == null) { res.Add(AutomapHelper.MergeInto <EmployeeVM>(employeeToVMmap, emp, new Department { departmentId = -1, departmentName = "None" } )); } else { var dep = unitOf.departmentRepository.GetById(tempDE.departmentId); res.Add(AutomapHelper.MergeInto <EmployeeVM>(employeeToVMmap, emp, dep)); } } } return(res); }
/// <summary> /// Convert/Clone data from the provided <paramref name="value"/> into a new instance of type <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The <see cref="Type"/> to convert to.</typeparam> /// <param name="value">The <see cref="object"/> to convert/clone data from</param> public static T ConvertTo <T>(object value) where T : new() { var results = new AutomapHelper().Automap <object, T>(value); return(results); }
public IEnumerable <DepartmentVM> GetAll() { ObservableCollection <DepartmentVM> res = new ObservableCollection <DepartmentVM>(); using (var unitOf = new UnitOfWork()) { var depList = unitOf.departmentRepository.GetList(); foreach (var dep in depList) { if (dep != null) { int numOfEmpl = unitOf.departmentEmployeeRepository.EmployeesInDepartment(dep); if (dep.numOfEmployees != numOfEmpl) { dep.numOfEmployees = numOfEmpl; unitOf.departmentRepository.Update(dep); } res.Add(AutomapHelper.MergeInto <DepartmentVM>(departmentVMmap, dep)); } else { throw new Exception("null department"); } } return(res); } }
partial void OnHandle(OrderUpdated @event) { Entities.OrderEntity entity = OrderRepository.Load(@event.Rsn); entity = AutomapHelper.Automap(@event, entity); OrderRepository.Update(entity); }
public DepartmentVM GetByName(string name) { if (string.IsNullOrEmpty(name)) { throw new Exception("Name of employee not set"); } using (var unitOf = new UnitOfWork()) { var department = unitOf.departmentRepository.GetByName(name); DepartmentVM departamentVM = new DepartmentVM(); if (department != null) { int numOfEmpl = unitOf.departmentEmployeeRepository.EmployeesInDepartment(department); if (department.numOfEmployees != numOfEmpl) { department.numOfEmployees = numOfEmpl; unitOf.departmentRepository.Update(department); } departamentVM = AutomapHelper.MergeInto <DepartmentVM>(departmentVMmap, department); } else { return(null); } return(departamentVM); } }
public void Handle(OrderCreated @event) { // As the entities match very closely, use the auto-mapper to save writing code. OrderEntity entity = AutomapHelper.Automap <OrderCreated, OrderEntity>(@event); // As this is the creation of a new order, pass the entity to the Repository for creation and persisted OrderRepository.Create(entity); }
public void Handle(OrderUpdated @event) { // As this is an update of an existing order, load the existing order OrderEntity entity = OrderRepository.Load(@event.Rsn); // As the entities match very closely, use the auto-mapper to save writing code. entity = AutomapHelper.Automap(@event, entity); // As this is an update of an existing order, pass the updated entity to the Repository to be updated and persisted OrderRepository.Update(entity); }
public IEnumerable <TaskVM> GetAll() { ObservableCollection <TaskVM> res = new ObservableCollection <TaskVM>(); using (var unitOf = new UnitOfWork()) { var taskList = unitOf.taskRepository.GetList(); foreach (var task in taskList) { res.Add(AutomapHelper.MergeInto <TaskVM>(taskVMmap, task)); } } return(res); }
public void Update(TaskVM taskVM) { using (var unitOf = new UnitOfWork()) { var task = unitOf.taskRepository.GetByIdDetached(taskVM.TaskId); if (task == null) { throw new Exception("Task not found id DB"); } task = AutomapHelper.MergeInto <EmplTask>(VMToTaskmap, taskVM); unitOf.taskRepository.Update(task); unitOf.Save(); } }
public void Update(DepartmentVM departamentVM) { using (var unitOf = new UnitOfWork()) { var department = unitOf.departmentRepository.GetByIdDetached(departamentVM.DepartmentId); if (department == null) { throw new Exception("Department not found id DB"); } var newDep = AutomapHelper.MergeInto <Department>(vmDepartment, departamentVM); unitOf.departmentRepository.Update(newDep); unitOf.Save(); } }
public void Add(DepartmentVM departmentVM) { Department department = new Department(); if (departmentVM == null) { } else { department = AutomapHelper.MergeInto <Department>(vmDepartment, departmentVM); } using (var unitOf = new UnitOfWork()) { unitOf.departmentRepository.Create(department); unitOf.Save(); } }
public void Update(EmployeeVM employeeVM) { using (var unitOf = new UnitOfWork()) { var employee = unitOf.employeeRepository.GetByIdDetached(employeeVM.EmployeeId); if (employee == null) { throw new Exception("Employee not found id DB"); } var depEmpl = unitOf.departmentEmployeeRepository.GetByEmployee(employee); var newDep = unitOf.departmentRepository.GetByName(employeeVM.DepartmentName); employee = AutomapHelper.MergeInto <Employee>(VMtoEmployeemap, employeeVM); unitOf.employeeRepository.Update(employee); if (depEmpl != null && newDep != null && depEmpl.departmentId != newDep.departmentId) { unitOf.departmentEmployeeRepository.Delete(depEmpl); DepartmentEmployee departmentEmployee = AutomapHelper.MergeInto <DepartmentEmployee>(ToDepEmpl, employee, newDep); departmentEmployee.department = newDep; departmentEmployee.employee = employee; unitOf.departmentEmployeeRepository.Create(departmentEmployee); } else if (depEmpl == null) { DepartmentEmployee departmentEmployee = AutomapHelper.MergeInto <DepartmentEmployee>(ToDepEmpl, employee, newDep); departmentEmployee.department = newDep; departmentEmployee.employee = employee; unitOf.departmentEmployeeRepository.Create(departmentEmployee); } unitOf.Save(); } }
public TaskVM GetById(int?id) { if (id == null) { throw new Exception("Id of task not set"); } using (var unitOf = new UnitOfWork()) { var task = unitOf.taskRepository.GetById(id.Value); if (task == null) { throw new Exception("task not found"); } var taskVM = AutomapHelper.MergeInto <TaskVM>(taskVMmap, task); return(taskVM); } }
public DepartmentVM GetById(int?id) { if (id == null) { throw new Exception("Id of employee not set"); } using (var unitOf = new UnitOfWork()) { var department = unitOf.departmentRepository.GetById(id.Value); DepartmentVM departamentVM = new DepartmentVM(); if (department != null) { departamentVM = AutomapHelper.MergeInto <DepartmentVM>(departmentVMmap, department); } else { return(null); } return(departamentVM); } }
public EmployeeVM GetById(int?id) { if (id == null) { throw new Exception("Id of employee not set"); } using (var unitOf = new UnitOfWork()) { var employee = unitOf.employeeRepository.GetById(id.Value); EmployeeVM employeeVM; if (employee == null) { throw new Exception("Employee not found"); } var departmentEmpl = unitOf.departmentEmployeeRepository.GetByEmployee(employee); if (departmentEmpl == null) { Department departament = new Department() { departmentId = -1, departmentName = "None" }; employeeVM = AutomapHelper.MergeInto <EmployeeVM>(employeeToVMmap, employee, departament); } else { employeeVM = AutomapHelper.MergeInto <EmployeeVM>(employeeToVMmap, employee, departmentEmpl.department); } return(employeeVM); } }
partial void OnHandle(OrderCreated @event) { Entities.OrderEntity entity = AutomapHelper.Automap <OrderCreated, Entities.OrderEntity>(@event); OrderRepository.Create(entity); }