/// <summary> /// Insert Task. /// </summary> /// <param name="task"></param> /// <returns></returns> /// <response code="200">Returns the newly-created item</response> /// <response code="400">If the item is null</response> public IHttpActionResult Post([FromBody] Task task) { try { List <string> errors = ValidateExtensions.ValidateTask(task); if (errors.Count > 0) { return(Content(HttpStatusCode.BadRequest, errors)); } task.Day = TimeUnit.Days.Get(task.Day.Id); task.Project = TimeUnit.Projects.Get(task.Day.Id); TimeUnit.Tasks.Insert(task); TimeUnit.Save(); Utility.Log($"ROLE CONTROLLER: Post Called on Role, Successfully added: {task.Description}.", "INFO"); return(Ok(TimeFactory.Create(task))); } catch (Exception ex) { Utility.Log($"ROLE CONTROLLER: Post Cannot be called on Role.", "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult Get(int id, int year = 0, int month = 0) { if (year == 0) { year = DateTime.Today.Year; } if (month == 0) { month = DateTime.Today.Month; } Employee emp = TimeUnit.Employees.Get(id); CalendarModel calendar = new CalendarModel(new BaseModel { Id = emp.Id, Name = emp.FullName }, year, month); var days = emp.Days.Where(x => x.Date.Value.Month == month && x.Date.Value.Year == year).ToList(); int i; foreach (var day in days) { i = day.Date.Value.Day - 1; calendar.Days[i].Id = day.Id; calendar.Days[i].Type = day.Category.Id; calendar.Days[i].Hours = day.Hours.Value; calendar.Days[i].Details = day.Assignments.Select(x => TimeFactory.Create(x)).ToArray(); } return(Ok(calendar)); }
/// <summary> /// Insert Engagement. /// </summary> /// <param name="engagement"></param> /// <returns></returns> /// <response code="200">Returns the newly-created item</response> /// <response code="400">If the item is null</response> public IHttpActionResult Post([FromBody] Engagement engagement) { try { List <string> errors = ValidateExtensions.ValidateEngagements(engagement); if (errors.Count > 0) { return(Content(HttpStatusCode.BadRequest, errors)); } engagement.Team = TimeUnit.Teams.Get(engagement.Team.Id); engagement.Role = TimeUnit.Roles.Get(engagement.Role.Id); engagement.Employee = TimeUnit.Employees.Get(engagement.Employee.Id); TimeUnit.Engagements.Insert(engagement); TimeUnit.Save(); Utility.Log($"ENGAGEMENT CONTROLLER: Post Called on Engagement, Successfully added: {engagement.Id}.", "INFO"); return(Ok(TimeFactory.Create(engagement))); } catch (Exception ex) { Utility.Log($"ENGAGEMENT CONTROLLER: Post Cannot be called on Engagement.", "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult GetById(int id) { //Employee employee = TimeUnit.Employees.Get(id); //if (employee == null) //{ // Utility.Log($"Failed to get data for employee with ID = {id}", "ERROR"); // return NotFound(); //} //else //{ // Utility.Log($"Get data for employee with ID = {id} ", "INFO"); // return Ok(TimeFactory.Create(employee)); //} //var claimsPrincipal = User as ClaimsPrincipal; //string username = claimsPrincipal.FindFirst //("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value; Employee employee = TimeUnit.Employees.Get(x => x.Id == id).FirstOrDefault(); if (employee == null) { Utility.Log($"Failed to get data for employee with ID = {id}", "ERROR"); return(NotFound()); } else { Utility.Log($"Get data for employee with ID = {id} ", "INFO"); return(Ok(TimeFactory.Create(employee))); } }
public IHttpActionResult Post([FromBody] Task task) { var errors = task.Validate(); if (errors.Count > 0) { string combindedString = string.Join(" ", errors.ToArray()); return(BadRequest(combindedString)); } try { task.Day = TimeUnit.Days.Get(task.Day.Id); task.Project = TimeUnit.Projects.Get(task.Project.Id); TimeUnit.Tasks.Insert(task); TimeUnit.Save(); Utility.Log($"Inserted new task.", "INFO"); return(Ok(TimeFactory.Create(task))); } catch (Exception ex) { Utility.Log($"Insert task failed.", "ERROR"); return(BadRequest(ex.Message)); } }
/// <summary> /// Update Customer by Id. /// </summary> /// <param name = "id"></param> /// <param name = "customer"></param> /// <returns></returns> /// <response code="200">Returns the newly-created item</response> /// <response code="400">If the item is null</response> public IHttpActionResult Put([FromBody] Customer customer, int id) { try { if (TimeUnit.Customers.Get(id) == null) { return(NotFound()); } List <string> errors = ValidateExtensions.ValidateCustomer(customer); if (errors.Count > 0) { return(Content(HttpStatusCode.BadRequest, errors)); } TimeUnit.Customers.Update(customer, id); //customer.Image = customer.ConvertAndSave(); TimeUnit.Save(); Utility.Log($"CUSTOMER CONTROLLER: Put Called on Customer, Successfully updated id: {id}.", "INFO"); return(Ok(TimeFactory.Create(customer))); } catch (Exception ex) { Utility.Log($"CUSTOMER CONTROLLER: Put Cannot be called on Customer.", "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult Post([FromBody] Employee employee) { var errors = employee.Validate(); if (errors.Count > 0) { string combindedString = string.Join(" ", errors.ToArray()); return(BadRequest(combindedString)); } employee.Position = TimeUnit.Roles.Get(x => x.Id == employee.Position.Id).FirstOrDefault(); try { employee.Image = employee.ConvertAndSave(); TimeUnit.Employees.Insert(employee); TimeUnit.Save(); Utility.Log($"Inserted new employee.", "INFO"); return(Ok(TimeFactory.Create(employee))); } catch (Exception ex) { Utility.Log($"Insert employee failed.", "ERROR"); return(BadRequest(ex.Message)); } }
public IHttpActionResult Post([FromBody] Engagement engagement) { var errors = engagement.Validate(); if (errors.Count > 0) { string combindedString = string.Join(" ", errors.ToArray()); return(BadRequest(combindedString)); } engagement.Team = TimeUnit.Teams.Get(engagement.Team.Id); engagement.Employee = TimeUnit.Employees.Get(engagement.Employee.Id); engagement.Role = TimeUnit.Roles.Get(engagement.Role.Id); try { TimeUnit.Engagements.Insert(engagement); TimeUnit.Save(); Utility.Log($"Inserted new engagement.", "INFO"); return(Ok(TimeFactory.Create(engagement))); } catch (Exception ex) { Utility.Log($"Insert engagement failed.", "ERROR"); return(BadRequest(ex.Message)); } }
public IHttpActionResult Put([FromBody] Engagement engagement, int id) { try { Engagement oldEngagement = TimeUnit.Engagements.Get(id); if (oldEngagement == null) { return(NotFound()); } engagement = FillEngagementWithOldData(engagement, oldEngagement); //engagement.Role = TimeUnit.Roles.Get(engagement.Role.Id); //engagement.Team = TimeUnit.Teams.Get(engagement.Team.Id); //engagement.Employee = TimeUnit.Employees.Get(engagement.Employee.Id); //engagement.RoleId = engagement.Role.Id; //engagement.TeamId = engagement.Team.Id; //engagement.EmployeeId = engagement.Employee.Id; TimeUnit.Engagements.Update(engagement, id); TimeUnit.Save(); Utility.Log($"Update data for ENGAGEMENT with ID = {id}", "INFO"); return(Ok(TimeFactory.Create(engagement))); } catch (Exception ex) { Utility.Log(ex.Message, "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult GetAll(string all = "") { //var list = TimeUnit.Employees.Get().ToList(); var list = TimeUnit.Employees.Get().ToList().Select(e => TimeFactory.Create(e)).ToList(); return(Ok(list)); }
public IHttpActionResult Put([FromBody] Customer customer, int id) { try { if (TimeUnit.Customer.Get(id) == null) { Utility.Log($"Update customer failed. Wrong id.", "ERROR"); return(NotFound()); } var errors = customer.Validate(); if (errors.Count > 0) { string combindedString = string.Join(" ", errors.ToArray()); return(BadRequest(combindedString)); } //customer.Address = TimeUnit.Customer.Get().Where(x => x.Id == id).Select(y => y.Address).FirstOrDefault(); TimeUnit.Customer.Update(customer, id); TimeUnit.Save(); Utility.Log($"Updated customer with id " + id + ".", "INFO"); return(Ok(TimeFactory.Create(customer))); } catch (Exception ex) { Utility.Log($"Update customer failed.", "ERROR"); return(BadRequest(ex.Message)); } }
public static string FromTimeInSeconds(long timeInSeconds) { return(TimeFactory.GetSumHours(timeInSeconds).ToString("D2") + ":" + TimeFactory.GetMinutes(timeInSeconds).ToString("D2") + ":" + TimeFactory.GetSeconds(timeInSeconds).ToString("D2") ); }
/// <summary> /// Update Team by Id. /// </summary> /// <param name="id"></param> /// <param name="team"></param> /// <returns></returns> /// <response code="200">Returns the newly-created item</response> /// <response code="400">If the item is null</response> public IHttpActionResult Put([FromBody] Team team, string id) { List <string> errors = ValidateExtensions.ValidateTeam(team); if (errors.Count > 0) { return(Content(HttpStatusCode.BadRequest, errors)); } try { if (TimeUnit.Teams.Get(id) == null) { return(NotFound()); } TimeUnit.Teams.Update(team, id); TimeUnit.Save(); Utility.Log($"ROLE CONTROLLER: Put Called on Role, Successfully updated id: {id}.", "INFO"); return(Ok(TimeFactory.Create(team))); } catch (Exception ex) { Utility.Log($"ROLE CONTROLLER: Put Cannot be called on Role.", "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult Post([FromBody] Employee employee) { try { List <string> errors = ValidateExtensions.ValidateEmployee(employee); if (errors.Count > 0) { return(Content(HttpStatusCode.BadRequest, errors)); } employee.Roles = TimeUnit.Roles.Get(employee.Roles.Id); employee.Image = employee.ConvertAndSave(); TimeUnit.Employees.Insert(employee); TimeUnit.Save(); Utility.Log($"EMPOLOYEE CONTROLLER: Post Called on Employee, Successfully added: {employee.FirstName + " " + employee.LastName}.", "INFO"); return(Ok(TimeFactory.Create(employee))); } catch (Exception ex) { Utility.Log($"EMPOLOYEE CONTROLLER: Post Cannot be called on Employee.", "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult Get(int id, int year = 0, int month = 0) { if (year == 0) { year = DateTime.Today.Year; } if (month == 0) { month = DateTime.Today.Month; } var emp = TimeUnit.Employees.Get(id); //CalendarModel calendar = new CalendarModel(new BaseModel { Id = emp.Id, Name = emp.FirstName + " " + emp.LastName}, year, month); CalendarModel calendar = new CalendarModel(emp.Id, year, month); var days = emp.Days.Where(x => x.Date.Month == month && x.Date.Year == year).ToList(); int i; foreach (var day in days) { i = day.Date.Day - 1; calendar.Days[i].Id = day.Id; calendar.Days[i].Type = (int)day.Type; calendar.Days[i].Hours = day.Hours; calendar.Days[i].Details = day.Tasks.Select(x => TimeFactory.Create(x)).ToArray(); //calendar.Days[i].Employee.Id = day.Employee.Id; //calendar.Days[i].Employee.Name = day.Employee.FirstName; calendar.Days[i].EmployeeId = day.Employee.Id; calendar.Days[i].EmployeeName = day.Employee.FirstName; } return(Ok(calendar)); }
/// <summary> /// Insert Project. /// </summary> /// <param name="project"></param> /// <returns></returns> /// <response code="200">Returns the newly-created item</response> /// <response code="400">If the item is null</response> public IHttpActionResult Post([FromBody] Project project) { try { List <string> errors = ValidateExtensions.ValidateProject(project); if (errors.Count > 0) { return(Content(HttpStatusCode.BadRequest, errors)); } project.Customer = TimeUnit.Customers.Get(project.CustomerId); project.Team = TimeUnit.Teams.Get(project.TeamId); TimeUnit.Projects.Insert(project); TimeUnit.Save(); Utility.Log($"PROJECT CONTROLLER: Post Called on Project, Successfully added: {project.Name}.", "INFO"); return(Ok(TimeFactory.Create(project))); } catch (Exception ex) { Utility.Log($"PROJECT CONTROLLER: Post Cannot be called on Project.", "ERROR", ex); return(BadRequest(ex.Message)); } }
/// <summary> /// Update Project by Id. /// </summary> /// <param name="id"></param> /// <param name="project"></param> /// <returns></returns> /// <response code="200">Returns the newly-created item</response> /// <response code="400">If the item is null</response> public IHttpActionResult Put([FromBody] Project project, int id) { try { Project oldProject = TimeUnit.Projects.Get(id); if (oldProject == null) { return(NotFound()); } project = FillNewProjectWithOldData(project, oldProject); //project.Customer = TimeUnit.Customers.Get(project.Customer.Id); //project.Team = TimeUnit.Teams.Get(project.Team.Id); //project.CustomerId = project.Customer.Id; //project.TeamId = project.Team.Id; TimeUnit.Projects.Update(project, id); TimeUnit.Save(); Utility.Log($"PROJECT CONTROLLER: Put Called on Project, Successfully updated id: {id}.", "INFO"); return(Ok(TimeFactory.Create(project))); } catch (Exception ex) { Utility.Log($"PROJECT CONTROLLER: Put Cannot be called on Project.", "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult Put([FromBody] Project project, int id) { try { Project oldProject = TimeUnit.Projects.Get(id); if (oldProject == null) { return(NotFound()); } project = FillNewProjectWithOldData(project, oldProject); //project.Customer = TimeUnit.Customers.Get(project.Customer.Id); //project.Team = TimeUnit.Teams.Get(project.Team.Id); //project.CustomerId = project.Customer.Id; //project.TeamId = project.Team.Id; TimeUnit.Projects.Update(project, id); TimeUnit.Save(); Utility.Log($"Update data for project with ID = {id}", "INFO"); return(Ok(TimeFactory.Create(project))); } catch (Exception ex) { Utility.Log(ex.Message, "ERROR", ex); return(BadRequest(ex.Message)); } }
public IHttpActionResult Put([FromBody] Engagement engagement, int id) { try { if (TimeUnit.Engagements.Get(id) == null) { Utility.Log($"Update engagement failed. Wrong id.", "ERROR"); return(NotFound()); } var errors = engagement.Validate(); if (errors.Count > 0) { string combindedString = string.Join(" ", errors.ToArray()); return(BadRequest(combindedString)); } TimeUnit.Engagements.Update(engagement, id); TimeUnit.Save(); Utility.Log($"Updated engagement with id " + id + ".", "INFO"); return(Ok(TimeFactory.Create(engagement))); } catch (Exception ex) { Utility.Log($"Update engagement failed.", "ERROR"); return(BadRequest(ex.Message)); } }
public IHttpActionResult Get() { var list = TimeUnit.Categories.Get().ToList() .Select(c => TimeFactory.Create(c)).ToList(); Utility.Log($"Get all data from CATEGORIES table", "INFO"); return(Ok(list)); }
public IHttpActionResult Get() { var list = TimeUnit.Roles.Get().ToList() .Select(r => TimeFactory.Create(r)) .ToList(); Utility.Log($"Get all data from ROLES table", "INFO"); return(Ok(list)); }
public IHttpActionResult Get() { var list = TimeUnit.Teams.Get().ToList() .Select(t => TimeFactory.Create(t)) .ToList(); Utility.Log($"Get all data from TEAMS table", "INFO"); return(Ok(list)); }
public IHttpActionResult Get() { var list = TimeUnit.Engagements.Get().ToList() .Select(t => TimeFactory.Create(t)) .ToList(); Utility.Log($"Get all data from ENGAGEMENTS table", "INFO"); return(Ok(list)); }
public static Time operator +(Time time, TimePeriod timePeriod) { long timeInSeconds = timePeriod.TimeInSeconds + time.TimeInSeconds; return(new Time( TimeFactory.GetHours(timeInSeconds), TimeFactory.GetMinutes(timeInSeconds), TimeFactory.GetSeconds(timeInSeconds) )); }
public static TimePeriod operator +(TimePeriod timePeriod1, TimePeriod timePeriod2) { long timeInSeconds = timePeriod1.TimeInSeconds + timePeriod2.TimeInSeconds; return(new TimePeriod( TimeFactory.GetSumHours(timeInSeconds), TimeFactory.GetMinutes(timeInSeconds), TimeFactory.GetSeconds(timeInSeconds) )); }
public MainPage() { InitializeComponent(); var panels = SetupGamePanels(); _levelFactory = new TimeLevelFactory(panels); _timeFactory = new TimeFactory(); _level = _levelFactory.CreateLevel(1); SetTimes(_level); }
public Time(string timeString) { this.Hours = (byte)TimeFactory.GetHours(timeString); this.Minutes = TimeFactory.GetMinutes(timeString); this.Seconds = TimeFactory.GetSeconds(timeString); TimeValidator.ValidateHours(this.Hours); TimeValidator.ValidateMinutes(this.Minutes); TimeValidator.ValidateSeconds(this.Seconds); this.TimeInSeconds = TimeToSecondHelper.Get(this.Hours, this.Minutes, this.Seconds); }
public TimePeriod(string timeString) { int hours = TimeFactory.GetHours(timeString); byte minutes = TimeFactory.GetMinutes(timeString); byte seconds = TimeFactory.GetSeconds(timeString); TimeValidator.ValidateHours(hours); TimeValidator.ValidateMinutes(minutes); TimeValidator.ValidateSeconds(seconds); this.TimeInSeconds = TimeToSecondHelper.Get(hours, minutes, seconds); }
public List <ProjectModel> Paginate(IQueryable <Project> query, int pageSize, int page) { ItemCount = TimeUnit.Projects.Get().Count(); TotalPages = (int)Math.Ceiling((double)ItemCount / pageSize); var list = query.Skip(pageSize * page) .Take(pageSize) .ToList() .Select(t => TimeFactory.Create(t)) .ToList(); return(list); }
public List <TeamModel> Paginate(IQueryable <Team> query, int pageSize, int page) { List <TeamModel> paginateList; ItemCount = TimeUnit.Teams.Get().Count(); TotalPages = (int)Math.Ceiling((double)ItemCount / pageSize); paginateList = query.Skip(pageSize * page) .Take(pageSize) .ToList() .Select(t => TimeFactory.Create(t, false)) .ToList(); return(paginateList); }