コード例 #1
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));
     }
 }
コード例 #2
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));
     }
 }
コード例 #3
0
ファイル: DaysController.cs プロジェクト: emmirsab/TimeKeeper
 /// <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));
     }
 }
コード例 #4
0
        public IHttpActionResult Get(int employeeId, int year = 0, int month = 0)
        {
            if (year == 0)
            {
                year = DateTime.Today.Year;
            }
            if (month == 0)
            {
                month = DateTime.Today.Month;
            }
            CalendarModel calendar   = new CalendarModel(TimeKeeperFactory.Create(employeeId), year, month);
            Employee      employee   = TimeKeeperUnit.Employees.Get(employeeId);
            var           listOfDays = employee.Days.Where(x => x.Date.Month == month && x.Date.Year == year).ToList();

            foreach (var day in listOfDays)
            {
                calendar.Days[day.Date.Day - 1].Id            = day.Id;
                calendar.Days[day.Date.Day - 1].Type          = (int)day.Type;
                calendar.Days[day.Date.Day - 1].Hours         = day.Hours;
                calendar.Days[day.Date.Day - 1].Details       = day.Details.Select(x => TimeKeeperFactory.Create(x)).ToArray();
                calendar.Days[day.Date.Day - 1].Employee.Name = employee.FullName;
                calendar.Days[day.Date.Day - 1].Employee.Id   = employee.Id;
            }

            Logger.Log("Returned calendar", "INFO");
            return(Ok(calendar));
        }
コード例 #5
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));
     }
 }
コード例 #6
0
        /// <summary>
        /// Get all Roles
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult Get()
        {
            var list = TimeKeeperUnit.Roles
                       .Get()
                       .AsEnumerable()
                       .Select(r => TimeKeeperFactory.Create(r))
                       .ToList();

            Logger.Log("Returned all roles", "INFO");
            return(Ok(list));
        }
コード例 #7
0
        public IHttpActionResult Get([FromUri] Header h)
        {
            var list = TimeKeeperUnit.Employees
                       .Get(x => x.FirstName.Contains(h.filter) || x.LastName.Contains(h.filter))
                       .AsQueryable()
                       .Header(h)
                       .Select(x => TimeKeeperFactory.Create(x))
                       .ToList();

            Logger.Log("Returned all records for employees", "INFO");
            return(Ok(list));
        }
コード例 #8
0
        /// <summary>
        /// Get all Engagements
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult Get(/*[FromUri] Header h*/)
        {
            var list = TimeKeeperUnit.Engagements
                       .Get(/*x => x.Employee.FullName.Contains(h.filter)*/)
                       //.AsQueryable()
                       //.Header(h)
                       .Select(x => TimeKeeperFactory.Create(x))
                       .ToList();

            Logger.Log("Returned all members", "INFO");
            return(Ok(list));
        }
コード例 #9
0
        /// <summary>
        /// Get all Teams
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult Get([FromUri] Header h)
        {
            var list = TimeKeeperUnit.Teams.Get()
                       .Where(x => x.Name.Contains(h.filter))
                       .Header(h)
                       .ToList()
                       .Select(t => TimeKeeperFactory.Create(t))
                       .ToList();

            Logger.Log("Returned all teams", "INFO");
            return(Ok(list)); //Ok - status 200
        }
コード例 #10
0
        public IHttpActionResult Get([FromUri] Header h)
        {
            var list = TimeKeeperUnit.Projects
                       .Get(x => x.Name.Contains(h.filter))
                       .AsQueryable()
                       .Header(h)
                       .ToList()
                       .Select(x => TimeKeeperFactory.Create(x))
                       .ToList();

            Logger.Log("Returned all projects", "INFO");
            return(Ok(list));
        }
コード例 #11
0
 ///// <summary>
 ///// Get all Tasks
 ///// </summary>
 ///// <returns></returns>
 //public IHttpActionResult Get([FromUri] Header h)
 //{
 //    var list = TimeKeeperUnit.Details
 //        .Get(x => x.Description.Contains(h.filter))
 //        .AsQueryable()
 //        .Header(h)
 //        .Select(x => TimeKeeperFactory.Create(x))
 //        .ToList();
 //    Logger.Log("Returned all tasks", "INFO");
 //    return Ok(list);
 //}
 /// <summary>
 /// Get specific Task
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public IHttpActionResult Get(int id)
 {
     Detail detail = TimeKeeperUnit.Details.Get(id);
     if (detail == null)
     {
         Logger.Log($"No task with id {id}");
         return NotFound();
     }
     else
     {
         Logger.Log($"Returned task with id {id}", "INFO");
         return Ok(TimeKeeperFactory.Create(detail));
     }
 }
コード例 #12
0
        /// <summary>
        /// Get specific Customer
        /// </summary>
        /// <param name="id"></param>
        /// <returns>A specific Customer</returns>
        public IHttpActionResult Get(int id)
        {
            Customer customer = TimeKeeperUnit.Customers.Get(id);

            if (customer == null)
            {
                Logger.Log($"Found no customer with id {id}");
                return(NotFound());
            }
            else
            {
                Logger.Log($"Returned customer with id {id}", "INFO");
                return(Ok(TimeKeeperFactory.Create(customer)));
            }
        }
コード例 #13
0
        /// <summary>
        /// Get specific Team
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Get(string id)
        {
            Team team = TimeKeeperUnit.Teams.Get(id);

            if (team == null)
            {
                Logger.Log($"No such team with id {id}");
                return(NotFound());
            }
            else
            {
                Logger.Log($"Returned team with id {id}", "INFO");
                return(Ok(TimeKeeperFactory.Create(team)));
            }
        }
コード例 #14
0
        /// <summary>
        /// Get specific Role
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Get(string id)
        {
            Role role = TimeKeeperUnit.Roles.Get(id);

            if (role == null)
            {
                Logger.Log($"No such role with id {id}");
                return(NotFound());
            }
            else
            {
                Logger.Log($"Returned role with id {id}", "INFO");
                return(Ok(TimeKeeperFactory.Create(role)));
            }
        }
コード例 #15
0
ファイル: DaysController.cs プロジェクト: emmirsab/TimeKeeper
        /// <summary>
        /// Get specific Day
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Get(int id)
        {
            Day day = TimeKeeperUnit.Calendar.Get(id);

            if (day == null)
            {
                Logger.Log($"No such day with id {id}");
                return(NotFound());
            }
            else
            {
                Logger.Log($"Returned day with id {id}", "INFO");
                return(Ok(TimeKeeperFactory.Create(day)));
            }
        }
コード例 #16
0
        /// <summary>
        /// Get specific Engagement
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IHttpActionResult Get(int id)
        {
            Engagement member = TimeKeeperUnit.Engagements.Get(id);

            if (member == null)
            {
                Logger.Log($"No such engagement with id {id}");
                return(NotFound());
            }
            else
            {
                Logger.Log($"Returned engagement with id {id}", "INFO");
                return(Ok(TimeKeeperFactory.Create(member)));
            }
        }
コード例 #17
0
        public IHttpActionResult Get(int id)
        {
            Project project = TimeKeeperUnit.Projects.Get(id);

            if (project == null)
            {
                Logger.Log($"No such project with id {id}");
                return(NotFound());
            }
            else
            {
                Logger.Log($"Returned project with id {id}", "INFO");
                return(Ok(TimeKeeperFactory.Create(project)));
            }
        }
コード例 #18
0
        UserModel BuildUser(string provider, string field)
        {
            Dictionary <string, string> token = new Dictionary <string, string>();
            UserModel CurrentUser             = new UserModel();

            if (HttpContext.Current.Request.Headers["Authorization"] != null)
            {
                string id_token = HttpContext.Current.Request.Headers.GetValues("Authorization").FirstOrDefault().Substring(7);
                string test     = HttpContext.Current.Request.Headers.GetValues("Authorization").FirstOrDefault();
                token = TokenUtility.GenToken(id_token);
                DateTime expTime = new DateTime(1970, 1, 1)
                                   .AddSeconds(Convert.ToDouble(token["exp"]));
                Employee emp = TimeKeeperUnit.Employees.Get(x => x.Email == token[field]).FirstOrDefault();
                CurrentUser = TimeKeeperFactory.Create(emp, provider);
            }
            return(CurrentUser);
        }
コード例 #19
0
        public IHttpActionResult Get(int id)
        {
            var      claimsPrincipal = User as ClaimsPrincipal;
            string   username        = claimsPrincipal.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;
            Employee emp             = TimeKeeperUnit.Employees.Get(x => x.Email == username).FirstOrDefault();

            if (emp == null)
            {
                Logger.Log($"No record of employee with id: {id}");
                return(NotFound());
            }
            else
            {
                Logger.Log($"Returned record for employee {emp.FullName}", "INFO");
                return(Ok(TimeKeeperFactory.Create(emp)));
            }
        }
コード例 #20
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));
     }
 }
コード例 #21
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));
     }
 }
コード例 #22
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));
     }
 }
コード例 #23
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));
            }
        }