/// <summary>
        /// Changes the value of Confirmed on the Hour Registration with the ID sent though the hourReg
        /// </summary>
        /// <param name="hourReg"></param>
        public int ConfirmHourRegistration(HourRegistrationDTO hourReg)
        {
            try
            {
                using (var db = new HourRegistrationEntities())
                {
                    var dbHour = db.HourRegistration.FirstOrDefault(x => x.ID == hourReg.Id);
                    dbHour.Confirmed = true;
                    dbHour.Denied = false;
                    db.SaveChanges();

                    db.HourRegistrationConfirmed.Add(new HourRegistrationConfirmed()
                    {
                        Login_ID = dbHour.LoginProject.Login_ID,
                        Project_ID = dbHour.LoginProject.Project_ID,
                        Head_ID = (long)dbHour.LoginProject.Login.Head_ID,
                        Hours = dbHour.Hours,
                        Comment = dbHour.Comment,
                        Date = dbHour.Date
                    });
                    db.SaveChanges();

                    return 1;
                }
            } catch (Exception e)
            {
                return -1;
            }
        }
 /// <summary>
 /// Correct a denied HourRegistration with the given parametres 
 /// </summary>
 /// <param name="hourReg"></param>
 public int CorrectDeneidHourRegistration(HourRegistrationDTO hourReg)
 {
     try
     {
         var actualDate = new String(hourReg.Date.ToCharArray().Where(c => c <= 255).ToArray());
         if (hourReg.Comment == "")
         {
             hourReg.Comment = "No comment";
         };
         using (var db = new HourRegistrationEntities())
         {
             var dbHour = db.HourRegistration.FirstOrDefault(x => x.ID == hourReg.Id);
             dbHour.Hours = hourReg.Hours;
             dbHour.Date = DateTime.Parse(actualDate);
             dbHour.Comment = hourReg.Comment;
             dbHour.Denied = false;
             db.SaveChanges();
             return 1;
         }
     }
     catch (DbEntityValidationException e)
     {
         return -2;
     }
     catch (Exception e)
     {
         return -1;
     }
 }
        /// <summary>
        /// Changes the value of Confirmed on the Hour Registration with the ID sent though the hourReg and adds a comment containing why it's been denied
        /// </summary>
        /// <param name="hourReg"></param>
        public int DenyHourRegistration(HourRegistrationDTO hourReg)
        {
            try
            {
                using (var db = new HourRegistrationEntities())
                {
                    var dbHour = db.HourRegistration.FirstOrDefault(x => x.ID == hourReg.Id);
                    dbHour.CommentDeny = hourReg.CommentDeny;
                    dbHour.Denied = true;
                    db.SaveChanges();

                    return 1;
                }
            }
            catch (Exception e)
            {
                return -1;
            }
        }
        /// <summary>
        /// Edits the HourRegistration with the given parametres
        /// </summary>
        /// <param name="hourRegistration"></param>
        public int EditHours(HourRegistrationDTO hourRegistration)
        {
            try
            {
                using (var db = new HourRegistrationEntities())
                {
                    var dbHour = db.HourRegistration.Single(x => x.ID == hourRegistration.Id);
                    dbHour.Date = DateTime.Parse(hourRegistration.Date);
                    dbHour.Hours = hourRegistration.Hours;
                    dbHour.Comment = hourRegistration.Comment;
                    db.SaveChanges();
                    return 1;
                }

            } catch(Exception e){
                return -1;
            }
        }
        /// <summary>
        /// Creates a new HourRegistration with the given parametres
        /// </summary>
        /// <param name="hourRegistration"></param>
        public int CreateHours(HourRegistrationDTO hourRegistration)
        {
            try
            {
                var actualDate = new String(hourRegistration.Date.ToCharArray().Where(c => c <= 255).ToArray());

                if (hourRegistration.Comment == "")
                {
                    hourRegistration.Comment = "No comment";
                }

                using (var db = new HourRegistrationEntities())
                {
                    var newLogin = new LoginProject()
                    {
                        Active = true,
                        Login_ID = hourRegistration.LoginProject.Login_Id,
                        Project_ID = hourRegistration.LoginProject.Project_Id
                    };

                    db.LoginProject.Add(newLogin);
                    db.SaveChanges();

                    long id = newLogin.ID;

                    db.HourRegistration.Add(new HourRegistration()
                    {
                        Date = DateTime.Parse(actualDate),
                        Hours = hourRegistration.Hours,
                        Comment = hourRegistration.Comment,
                        LoginProject_ID = id,
                        Confirmed = false,
                        Denied = false
                    });

                    db.SaveChanges();
                    return 1;
                }
            }
            catch (DbEntityValidationException e)
            {
                return -2;
            }
            catch (Exception e)
            {
              return -1;
            }
        }