//PROJECT OPERTIONS
        /// <summary>
        /// Returns all Projects
        /// </summary>
        /// <returns>A list of ProjectDTO</returns>
        public List<ProjectDTO> GetAllProjects(string take, string skip, string searchValue)
        {
            var projectList = new List<ProjectDTO>();
            try
            {
                var takeInt = Int32.Parse(take);
                var skipInt = Int32.Parse(skip);
                using (var db = new HourRegistrationEntities())
                {
                    var dbList = new List<Project>();
                    if (searchValue != "null")
                    {
                        dbList =
                            db.Project.OrderBy(x => x.Title)
                            .Where(x => x.Title.Contains(searchValue))
                            .Skip(skipInt)
                            .Take(takeInt)
                            .ToList();
                    }
                    else
                    {
                        dbList = db.Project.OrderBy(x => x.Title).Skip(skipInt).Take(takeInt).ToList();
                    }

                    //If the list from the DB is empty
                    if (dbList.Count == 0)
                    {
                        return projectList;
                    }

                    foreach (var project in dbList)
                    {
                        var proj = new ProjectDTO()
                        {
                            Id = project.ID,
                            Title = project.Title,
                            Cust_id = project.Cust_ID,
                            Customer = new CustomerDTO()
                            {
                            Id = project.Cust.ID,
                            Name = project.Cust.Name,
                            }
                        };
                        projectList.Add(proj);
                    }
                    return projectList;
                }
            }
            catch (Exception e)
            {
                return projectList;
            }
        }
        /// <summary>
        /// Returns all Projects with the given Login.ID, stringId
        /// </summary>
        /// <param name="stringId"></param>
        /// <returns>A list of ProjectDTO</returns>
        public List<ProjectDTO> GetAllProjectsWithLoginId(string stringId)
        {
            var projectList = new List<ProjectDTO>();
            try
            {
                using (var db = new HourRegistrationEntities())
                {
                    var list = db.Project.ToList();
                    int loginId = Int32.Parse(stringId);
                    //If the list from the DB is empty
                    if (list.Count == 0)
                    {
                        return projectList;
                    }
                    foreach (var project in list)
                    {
                        var active = false;
                        try
                        {
                            active = (bool)db.LoginProject
                                .FirstOrDefault(x => x.Login_ID == loginId && x.Project_ID == project.ID)
                                .Active;
                        }
                        catch (Exception e)
                        {

                        }

                        var proj = new ProjectDTO()
                        {
                            Id = project.ID,
                            Title = project.Title,
                            Cust_id = project.Cust_ID,
                            Customer = new CustomerDTO()
                            {
                                Id = project.Cust.ID,
                                Name = project.Cust.Name,
                            },
                            LoginActive = active
                        };
                        projectList.Add(proj);
                    }
                }
                return projectList;
            }
            catch(Exception e)
            {
              return projectList;
            }
        }
        /// <summary>
        /// Creates a new Project with the given parametres
        /// </summary>
        /// <param name="project"></param>
        public int CreateProject(ProjectDTO project)
        {
            try
            {
                using (var db = new HourRegistrationEntities())
                {
                    var cust = db.Cust.SingleOrDefault(x => x.Name == project.Customer.Name);
                    if (cust != null)
                    {
                        db.Project.Add(new Project()
                        {
                            Title = project.Title,
                            Cust_ID = cust.ID
                        });

                        db.SaveChanges();
                    }
                    else
                    {
                        var newCust = new Cust()
                        {
                            Name = project.Customer.Name
                        };

                        db.Cust.Add(newCust);
                        db.SaveChanges();

                        var custId = newCust.ID;

                        db.Project.Add(new Project()
                        {
                            Title = project.Title,
                            Cust_ID = custId
                        });

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