Esempio n. 1
0
        public ExcuseDTO Get(int id)
        {
            var ex = _context.Excuses.Include(e => e.Employee).ThenInclude(e => e.Profession)
                     .FirstOrDefault(e => e.ID == id);
            ExcuseDTO excuseDTO = new ExcuseDTO
            {
                ID             = ex.ID,
                Approved       = ex.Approved,
                Comment        = ex.Comment,
                Date           = ex.Date,
                ProfessionName = ex.Employee.Profession.Name,
                EmployeeName   = ex.Employee.Name,
                Hours          = ex.Hours,
                Time           = ex.Time
            };

            if (excuseDTO == null)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content    = new StringContent("Excuse doesn't exist", System.Text.Encoding.UTF8, "text/plain"),
                    StatusCode = HttpStatusCode.NotFound
                };
                throw new HttpResponseException(response);
            }
            else
            {
                return(excuseDTO);
            }
        }
Esempio n. 2
0
        public ActionResult <ExcuseDTO> GetExcuse(int id)
        {
            var ex = _context.Excuses.Include(e => e.Employee).ThenInclude(e => e.Profession)
                     .FirstOrDefault(e => e.ID == id);

            if (ex == null)
            {
                return(NotFound());
            }
            ExcuseDTO excuseDTO = new ExcuseDTO
            {
                ID             = ex.ID,
                Approved       = ex.Approved,
                Comment        = ex.Comment,
                Date           = ex.Date,
                ProfessionName = ex.Employee.Profession.Name,
                EmployeeName   = ex.Employee.Name,
                Hours          = ex.Hours,
                Time           = ex.Time
            };

            return(excuseDTO);
        }