Esempio n. 1
0
 /// <summary>
 /// Update chosen Day
 /// </summary>
 /// <param name="day"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public IHttpActionResult Put([FromBody] CalendarModel day, int id)
 {
     try
     {
         if (TimeKeeperUnit.Calendar.Get(id) == null)
         {
             Logger.Log($"No such day with id {id}");
             return(NotFound());
         }
         if (!ModelState.IsValid)
         {
             var message = $"Failed updating day with id {id}, " + Environment.NewLine;
             message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
             throw new Exception(message);
         }
         TimeKeeperUnit.Calendar.Update(TimeKeeperFactory.Create(day, TimeKeeperUnit), id);
         TimeKeeperUnit.Save();
         Logger.Log($"Updated day with id {id}", "INFO");
         return(Ok(day));
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 2
0
 public IHttpActionResult Put([FromBody] EmployeeModel emp, int id)
 {
     try
     {
         if (TimeKeeperUnit.Employees.Get(id) == null)
         {
             Logger.Log($"No existing employee with id {id}");
             return(NotFound());
         }
         if (!ModelState.IsValid)
         {
             string message = $"Failed updating employee with id {id}" + Environment.NewLine;
             message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
             throw new Exception(message);
         }
         TimeKeeperUnit.Employees.Update(TimeKeeperFactory.Create(emp, TimeKeeperUnit), id);
         TimeKeeperUnit.Save();
         Logger.Log($"Updated record for employee {emp.FullName}", "INFO");
         return(Ok(emp));
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 3
0
 public IHttpActionResult Put(EngagementModel e, int id)
 {
     try
     {
         if (TimeKeeperUnit.Engagements.Get(id) == null)
         {
             Logger.Log($"No such member with id {id}");
             return(NotFound());
         }
         if (!ModelState.IsValid)
         {
             string message = "Failed inserting new member, " + Environment.NewLine;
             message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
             throw new Exception(message);
         }
         TimeKeeperUnit.Engagements.Update(TimeKeeperFactory.Create(e, TimeKeeperUnit), id);
         TimeKeeperUnit.Save();
         Logger.Log($"Updated member {e.Employee.Name}", "INFO");
         return(Ok(e));
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Update chosen Team
 /// </summary>
 /// <param name="team"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public IHttpActionResult Put([FromBody] TeamModel team, string id)
 {
     try
     {
         if (TimeKeeperUnit.Teams.Get(id) == null)
         {
             Logger.Log($"No such team with id {id}");
             return(NotFound());
         }
         if (!ModelState.IsValid)
         {
             var message = $"Failed updating team with id {id}" + Environment.NewLine;
             message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
             throw new Exception(message);
         }
         TimeKeeperUnit.Teams.Update(TimeKeeperFactory.Create(team, TimeKeeperUnit), id);
         TimeKeeperUnit.Save();
         Logger.Log($"Updated team with id {id}", "INFO");
         return(Ok(team));
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Insert new Day
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IHttpActionResult Post([FromBody] DayModel model)
        {
            try
            {
                Day day = new Day
                {
                    Id       = model.Id,
                    Date     = model.Date,
                    Type     = (DayType)model.Type,
                    Hours    = model.Hours,
                    Employee = TimeKeeperUnit.Employees.Get(model.Employee.Id)
                };
                if (day.Id == 0)
                {
                    TimeKeeperUnit.Calendar.Insert(day);
                }
                else
                {
                    TimeKeeperUnit.Calendar.Update(day, day.Id);
                }
                TimeKeeperUnit.Save();

                foreach (DetailModel task in model.Details)
                {
                    if (task.Deleted && task.Id != 0)
                    {
                        TimeKeeperUnit.Details.Delete(TimeKeeperUnit.Details.Get(task.Id));
                    }
                    else
                    {
                        Detail detail = new Detail
                        {
                            Id          = task.Id,
                            Day         = TimeKeeperUnit.Calendar.Get(day.Id),
                            Description = task.Description,
                            Hours       = task.Hours,
                            Project     = TimeKeeperUnit.Projects.Get(task.Project.Id)
                        };
                        if (detail.Id == 0)
                        {
                            TimeKeeperUnit.Details.Insert(detail);
                        }
                        else
                        {
                            TimeKeeperUnit.Details.Update(detail, detail.Id);
                        }
                    }
                }
                TimeKeeperUnit.Save();
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 6
0
        public IHttpActionResult Delete(int id)
        {
            try
            {
                Project project = TimeKeeperUnit.Projects.Get(id);
                if (project == null)
                {
                    Logger.Log($"No such project with id {id}");
                    return(NotFound());
                }

                TimeKeeperUnit.Projects.Delete(project);
                TimeKeeperUnit.Save();
                return(Ok());
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Insert new Role
 /// </summary>
 /// <param name="role"></param>
 /// <returns></returns>
 public IHttpActionResult Post([FromBody] RoleModel role)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             string message = "Failed inserting new role" + Environment.NewLine;
             message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
             throw new Exception(message);
         }
         TimeKeeperUnit.Roles.Insert(TimeKeeperFactory.Create(role, TimeKeeperUnit));
         TimeKeeperUnit.Save();
         Logger.Log("Inserted new role", "INFO");
         return(Ok(role));
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Insert new Team
 /// </summary>
 /// <param name="team"></param>
 /// <returns></returns>
 public IHttpActionResult Post([FromBody] TeamModel team)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             var message = "Failed inserting new team" + Environment.NewLine;
             message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
             throw new Exception(message);
         }
         TimeKeeperUnit.Teams.Insert(TimeKeeperFactory.Create(team, TimeKeeperUnit));
         TimeKeeperUnit.Save();
         Logger.Log("Inserted new team", "INFO");
         return(Ok(team));
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 9
0
 public IHttpActionResult Post(EngagementModel e)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             string message = "Failed inserting new member, " + Environment.NewLine;
             message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
             throw new Exception(message);
         }
         TimeKeeperUnit.Engagements.Insert(TimeKeeperFactory.Create(e, TimeKeeperUnit));
         TimeKeeperUnit.Save();
         Logger.Log($"Inserted new member {e.Employee.Name}", "INFO");
         return(Ok(new { e, memberId = TimeKeeperUnit.Engagements.Get().Count() }));
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Delete chosen Task
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public IHttpActionResult Delete(int id)
 {
     try
     {
         Detail detail = TimeKeeperUnit.Details.Get(id);
         if (detail == null)
         {
             Logger.Log($"No such task with id {id}");
             return NotFound();
         }
         TimeKeeperUnit.Details.Delete(detail);
         TimeKeeperUnit.Save();
         Logger.Log($"Deleted task with id {id}", "INFO");
         return Ok();
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return BadRequest(ex.Message);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Delete chosen Role
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Delete(string id)
        {
            try
            {
                Role role = TimeKeeperUnit.Roles.Get(id);
                if (role == null)
                {
                    Logger.Log($"No such role with id {id}");
                    return(NotFound());
                }

                TimeKeeperUnit.Roles.Delete(role);
                TimeKeeperUnit.Save();
                Logger.Log($"Deleted role with id {id}");
                return(Ok());
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Delete chosen customer
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Deleted wanted Customer</returns>
        public IHttpActionResult Delete(int id)
        {
            try
            {
                Customer customer = TimeKeeperUnit.Customers.Get(id);
                if (customer == null)
                {
                    Logger.Log($"No customer found with id {id}");
                    return(NotFound());
                }

                TimeKeeperUnit.Customers.Delete(customer);
                TimeKeeperUnit.Save();
                Logger.Log($"Deleted customer with id {id}", "INFO");
                return(Ok());
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Delete chosen Day
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Delete(int id)
        {
            try
            {
                Day day = TimeKeeperUnit.Calendar.Get(id);
                if (day == null)
                {
                    Logger.Log($"No such day with id {id}");
                    return(NotFound());
                }

                TimeKeeperUnit.Calendar.Delete(day);
                TimeKeeperUnit.Save();
                Logger.Log($"Deleted day with id {id}", "INFO");
                return(Ok());
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 14
0
        public IHttpActionResult Delete(int id)
        {
            try
            {
                var e = TimeKeeperUnit.Engagements.Get(id);
                if (e == null)
                {
                    Logger.Log($"No member found with id {id}");
                    return(NotFound());
                }

                TimeKeeperUnit.Engagements.Delete(e);
                TimeKeeperUnit.Save();
                Logger.Log($"Deleted member with id {id}", "INFO");
                return(Ok());
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, "ERROR", e);
                return(BadRequest(e.Message));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Delete chosen Engagement
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Delete(int id)
        {
            try
            {
                Engagement member = TimeKeeperUnit.Engagements.Get(id);
                if (member == null)
                {
                    Logger.Log($"No such engagement with id {id}");
                    return(NotFound());
                }

                TimeKeeperUnit.Engagements.Delete(member);
                TimeKeeperUnit.Save();
                Logger.Log($"Deleted engagement with id {id}", "INFO");
                return(Ok());
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Delete chosen Team
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public IHttpActionResult Delete(string id)
 {
     try
     {
         Team team = TimeKeeperUnit.Teams.Get(id);
         if (team == null)
         {
             Logger.Log($"No such team with id {id}");
             return(NotFound());
         }
         TimeKeeperUnit.Projects.Delete(team.Projects);
         TimeKeeperUnit.Engagements.Delete(team.Engagements);
         TimeKeeperUnit.Teams.Delete(team);
         TimeKeeperUnit.Save();
         Logger.Log($"Deleted team with id {id}", "INFO");
         return(Ok());
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message, "ERROR", ex);
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 17
0
        /// <summary>
        /// Insert new customer
        /// </summary>
        /// <param name="customer"></param>
        /// <returns>A new Customer</returns>
        public IHttpActionResult Post([FromBody] CustomerModel customer)
        {
            if (customer.Monogram == null)
            {
                customer.Monogram = "";
                foreach (var item in customer.Name)
                {
                    if (customer.Monogram.Length > 3)
                    {
                        break;
                    }

                    if (char.IsUpper(item))
                    {
                        customer.Monogram += item;
                    }
                }
            }
            try
            {
                if (!ModelState.IsValid)
                {
                    var message = "Failed inserting new customer" + Environment.NewLine;
                    message += string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                    throw new Exception(message);
                }
                TimeKeeperUnit.Customers.Insert(TimeKeeperFactory.Create(customer, TimeKeeperUnit));
                TimeKeeperUnit.Save();
                Logger.Log($"Inserted new customer with name {customer.Name}", "INFO");
                return(Ok(customer));
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 18
0
        public IHttpActionResult Delete(int id)
        {
            try
            {
                Employee emp = TimeKeeperUnit.Employees.Get(id);
                if (emp == null)
                {
                    Logger.Log($"No such employee with id {id}");
                    return(NotFound());
                }
                TimeKeeperUnit.Details.Delete(emp.Days.SelectMany(x => x.Details));

                TimeKeeperUnit.Calendar.Delete(emp.Days);
                TimeKeeperUnit.Employees.Delete(emp);
                TimeKeeperUnit.Save();
                Logger.Log($"Deleted employee with id {id}", "INFO");
                return(Ok());
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }