public async Task <bool> Update(EmployeeDTM employeeDtm) { try { Employee employee = new Employee(); employee.Id = employeeDtm.Id; if (employeeDtm.CalendarSetting != null) { employee.CalendarSetting = ModelFactory.changeFromDTM(employeeDtm.CalendarSetting); } if (employeeDtm.CustomerNotification != null) { employee.CustomerNotification = ModelFactory.changeFromDTM(employeeDtm.CustomerNotification); } if (employeeDtm.TeamNotification != null) { employee.TeamNotification = ModelFactory.changeFromDTM(employeeDtm.TeamNotification); } if (employeeDtm.Permission != null) { employee.Permission = ModelFactory.changeFromDTM(employeeDtm.Permission); } if (employeeDtm.WorkingHour != null) { employee.WorkingHour = ModelFactory.changeFromDTM(employeeDtm.WorkingHour); } return(await Database.Employees.Update(employee) ? true : false); } catch (Exception ex) { Console.Out.WriteLine(ex.Message); return(false); } }
// POST: Employees/employeesDTM public async Task <HttpResponseMessage> Post([FromBody] EmployeeDTM employeeDTM) { try { int id = await TheRepo.EmployeesDTM.Create(employeeDTM); return(Request.CreateResponse(HttpStatusCode.Created, id)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public async Task <int> Create(EmployeeDTM item) { try { Employee employee = new Employee(); employee.Business = await Database.Businesses.Get(item.Business.Id); employee.BusinessId = item.Business.Id; employee.User = await Database.Users.Get(item.User.Id); employee.UserId = item.User.Id; employee.IsOwner = item.IsOwner; await Database.Employees.Create(employee); if (employee.IsOwner == false) { WorkingHour wHourDtm = new WorkingHour(); wHourDtm.Employee = employee; wHourDtm.EmployeeId = employee.Id; await Database.WorkingHours.Create(wHourDtm); Permission perm = new Permission(); perm.Employee = employee; perm.EmployeeId = employee.Id; await Database.Permissions.Create(perm); CalendarSetting cSetting = new CalendarSetting(); cSetting.Employee = employee; cSetting.EmployeeId = employee.Id; await Database.CalendarSettings.Create(cSetting); CustomerNotification cNotif = new CustomerNotification(); cNotif.Employee = employee; cNotif.EmployeeId = employee.Id; await Database.CustomerNotifications.Create(cNotif); TeamNotification tNotif = new TeamNotification(); tNotif.Employee = employee; tNotif.EmployeeId = employee.Id; await Database.TeamNotifications.Create(tNotif); } return(employee.Id); } catch { return(0); } }
public static EmployeeDTM changeToDTM(Employee employee) { EmployeeDTM employeeDtm = new EmployeeDTM(); employeeDtm.Id = employee.Id; if (employee.Business != null) { employeeDtm.Business = changeToDTM(employee.Business); employeeDtm.BusinessId = employee.Business.Id; } if (employee.User != null) { employeeDtm.User = changeToDTM(employee.User); employeeDtm.UserId = employee.User.Id; } employeeDtm.IsOwner = employee.IsOwner; if (employee.CalendarSetting != null) { employeeDtm.CalendarSetting = changeToDTM(employee.CalendarSetting); } if (employee.CustomerNotification != null) { employeeDtm.CustomerNotification = changeToDTM(employee.CustomerNotification); } if (employee.TeamNotification != null) { employeeDtm.TeamNotification = changeToDTM(employee.TeamNotification); } if (employee.Permission != null) { employeeDtm.Permission = changeToDTM(employee.Permission); } if (employee.WorkingHour != null) { employeeDtm.WorkingHour = changeToDTM(employee.WorkingHour); } //if (employee.Slot != null) //{ // employeeDtm.Slot = changeToDTM(employee.Slot); //} return(employeeDtm); }
public static Employee changeFromDTM(EmployeeDTM employeeDtm) { Employee employee = new Employee(); employee.Id = employeeDtm.Id; employee.Business = changeFromDTM(employeeDtm.Business); employee.BusinessId = employeeDtm.Business.Id; employee.User = changeFromDTM(employeeDtm.User); employee.UserId = employeeDtm.User.Id; employee.IsOwner = employeeDtm.IsOwner; if (employeeDtm.CalendarSetting != null) { CalendarSetting cset = new CalendarSetting(); cset = changeFromDTM(employeeDtm.CalendarSetting); employee.CalendarSetting = cset; } if (employeeDtm.CustomerNotification != null) { CustomerNotification cNotice = new CustomerNotification(); cNotice = changeFromDTM(employeeDtm.CustomerNotification); employee.CustomerNotification = cNotice; } if (employeeDtm.TeamNotification != null) { TeamNotification tNotice = new TeamNotification(); tNotice = changeFromDTM(employeeDtm.TeamNotification); employee.TeamNotification = tNotice; } if (employeeDtm.Permission != null) { Permission permission = new Permission(); permission = changeFromDTM(employeeDtm.Permission); employee.Permission = permission; } if (employeeDtm.WorkingHour != null) { WorkingHour wHour = new WorkingHour(); wHour = changeFromDTM(employeeDtm.WorkingHour); employee.WorkingHour = wHour; } return(employee); }
public async Task <EmployeeDTM> Get(int id) { int firstEmployeeId = 1; if (id < firstEmployeeId) { throw new ValidationException("Employee id is not specified correctly", ""); } var employee = await Database.Employees.Get(id); if (employee == null) { throw new ValidationException("Employee is not found", ""); } EmployeeDTM employeeDTM = ModelFactory.changeToDTM(employee); return(employeeDTM); }
public async Task <HttpResponseMessage> Put([FromBody] EmployeeDTM employeeDTM) { try { var originalEmployee = TheRepo.EmployeesDTM.Get(employeeDTM.Id); if (originalEmployee == null) { return(Request.CreateResponse(HttpStatusCode.NotModified, "Item is not found")); } else { await TheRepo.EmployeesDTM.Update(employeeDTM); return(Request.CreateResponse(HttpStatusCode.OK, employeeDTM)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }