Example #1
0
        public StaffDetailDTO Get(string staffCode)
        {
            if (String.IsNullOrEmpty(staffCode))
            {
                throw new HttpException(400, "Bad Request"); // If an ID isn't provided in the URL, a HTTP 400 exception is thrown
            }

            var thisStaff = context.Staffs.FirstOrDefault(s => s.staffCode.Equals(staffCode, StringComparison.OrdinalIgnoreCase) && s.Active == true); // Gets the staff member where the code equals the ID from the URL, regardless of case, and isn't soft deleted - equals null if not found

            if (thisStaff == null)
            {
                throw new HttpException(404, "Not Found"); // If the staff member doesn't exist for the given ID, a HTTP 404 exception is thrown
            }
            else
            {
                var dto = StaffDetailDTO.buildDTO(thisStaff); // Passes the collection to the Staff Data Transfer Object to be formatted
                return(dto);
            }
        }