コード例 #1
0
        public HttpResponseMessage GetProjectTimeRecords([FromBody] int projectId)

        {
            if (projectId != 0)
            {
                var            records            = repo.GetProjectTimeRecords(projectId);
                List <TimeDTO> ProjectTimeRecords = new List <TimeDTO>();

                if (records == null || records.Count() == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "No Records were found."));
                }
                else
                {
                    EntityToDTO etd = new EntityToDTO();

                    foreach (var r in records)
                    {
                        r.TimeSpent = CalculateProjectHours(r);
                        TimeDTO timeDTO = etd.TimeEntityToDTO(r);
                        if (timeDTO != null)
                        {
                            ProjectTimeRecords.Add(timeDTO);
                        }
                    }
                    ;

                    return(Request.CreateResponse(HttpStatusCode.OK, ProjectTimeRecords));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "An error Occured"));
            }
        }
コード例 #2
0
        public void EntityToTimeDTOValid()
        {
            EntityToDTO etd = new EntityToDTO();

            Time expected = new Time {
                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 = etd.TimeEntityToDTO(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);
        }