public HttpResponseMessage UpdateProjectOwner(ProjectOwnerDTO projectOwner)
 {
     if (projectOwner != null)
     {
         DTOToEntity dte   = new DTOToEntity();
         var         owner = dte.OwnerDTOToEntity(projectOwner);
         repo.AddProjectOwner(owner);
         return(Request.CreateResponse(HttpStatusCode.OK, "Owner Added Successfully."));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "An Error Occured. Please check your details and try again."));
     }
 }
        public HttpResponseMessage UpdateProject([FromBody] ProjectDTO project)
        {
            if (project != null)
            {
                DTOToEntity dte            = new DTOToEntity();
                var         updatedProject = dte.ProjectDTOToEntity(project);
                repo.UpdateProject(updatedProject);

                return(Request.CreateResponse(HttpStatusCode.OK, "Project Updated successfully."));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "An error occured."));
            }
        }
        public void ProjectDTOToEntityExistingValid()
        {
            ProjectController pc = new ProjectController();

            DTOToEntity dte = new DTOToEntity();

            ProjectDTO expected = new ProjectDTO {
                Id = 1, Invoiced = false, ProjectName = "Test Project", ProjectDescription = "Test Description"
            };
            var actual = dte.ProjectDTOToEntity(expected);

            Assert.AreNotEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.ProjectName, actual.ProjectName);
            Assert.AreEqual(expected.ProjectDescription, actual.ProjectDescription);
            Assert.AreEqual(expected.Invoiced, actual.Invoiced);
        }
        public HttpResponseMessage UpdateTime([FromBody] TimeDTO time)
        {
            if (time != null)
            {
                DTOToEntity dte    = new DTOToEntity();
                var         entity = dte.TimeDTOToEntity(time);

                repo.UpdateTime(entity);

                return(Request.CreateResponse(HttpStatusCode.OK, "Time changed successfully."));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "An error Occured"));
            }
        }
        public HttpResponseMessage AddNewProject([FromBody] ProjectDTO project)
        {
            if (project != null)
            {
                DTOToEntity dte = new DTOToEntity();

                Project newProject = dte.ProjectDTOToEntity(project);

                repo.AddNewProject(newProject);

                return(Request.CreateResponse(HttpStatusCode.OK, "Project added successfully."));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The project contained no information. Please fill in the form and try again."));
            }
        }
        public void TimeDTOToEntityValid()
        {
            DTOToEntity dte = new DTOToEntity();

            TimeDTO expected = new TimeDTO {
                Id = 1, Project_Id = 1, Date = DateTime.Now, TimeStart = new DateTime(2017, 08, 26, 08, 00, 00), TimeEnd = new DateTime(2017, 08, 26, 10, 00, 00), IsInvoiced = false, Description = "Test description"
            };

            var actual = dte.TimeDTOToEntity(expected);

            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Project_Id, actual.Project_Id);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.Date, actual.Date);
            Assert.AreEqual(expected.TimeStart, actual.TimeStart);
            Assert.AreEqual(expected.TimeEnd, actual.TimeEnd);
            Assert.AreEqual(expected.IsInvoiced, actual.IsInvoiced);
        }
        public HttpResponseMessage AddTime([FromBody] TimeDTO newTime)
        {
            if (newTime != null)
            {
                DTOToEntity dte = new DTOToEntity();

                newTime.Date       = DateTime.Now;
                newTime.IsInvoiced = false;
                var entity = dte.TimeDTOToEntity(newTime);

                repo.AddTime(entity);
                return(Request.CreateResponse(HttpStatusCode.OK, "Time uploaded successfully."));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "An error Occured"));
            }
        }
        public void OwnerDTOToEntityExistingValid()
        {
            ProjectOwnerController poc = new ProjectOwnerController();

            DTOToEntity dte = new DTOToEntity();

            ProjectOwnerDTO expected = new ProjectOwnerDTO {
                Id = 1, Project_Id = 1, Name = "Test", PhoneNumber = "00000 000000", AddressLine1 = "address 1", AddressLine2 = "address 2", Town = "town", County = "county", PostCode = "postcode"
            };

            var actual = dte.OwnerDTOToEntity(expected);

            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Project_Id, actual.Project_Id);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.PhoneNumber, actual.PhoneNumber);
            Assert.AreEqual(expected.AddressLine1, actual.AddressLine1);
            Assert.AreEqual(expected.AddressLine2, actual.AddressLine2);
            Assert.AreEqual(expected.Town, actual.Town);
            Assert.AreEqual(expected.County, actual.County);
            Assert.AreEqual(expected.PostCode, actual.PostCode);
        }