Esempio n. 1
0
        /// <summary>
        /// This method is used to add an item to a queue
        /// </summary>
        /// <param name="request">The information of the queue item</param>
        /// <returns>Response which indicates success or failure</returns>
        public AddToQueueResponse AddToQueue(AddToQueueRequest request)
        {
            AddToQueueResponse response = new AddToQueueResponse();

            try
            {
                response = (AddToQueueResponse)request.CheckValidation(response);

                if (response.Status == HttpStatusCode.BadRequest)
                {
                    return(response);
                }

                StudentFacade studentFacade = new StudentFacade();

                if (!request.StudentID.HasValue)
                {
                    var addResponse = studentFacade.AddStudentNickname(new AddStudentRequest()
                    {
                        Nickname = request.Nickname,
                        SID      = request.SID
                    });

                    if (addResponse.Status != HttpStatusCode.OK)
                    {
                        response.Status         = addResponse.Status;
                        response.StatusMessages = addResponse.StatusMessages;
                        return(response);
                    }

                    request.StudentID = addResponse.StudentID;
                }

                QueueDataLayer dataLayer = new QueueDataLayer();
                int            itemId    = dataLayer.AddToQueue(request);

                response.ItemId = itemId;
                response.Status = HttpStatusCode.OK;
            }
            catch (NotFoundException ex)
            {
                s_logger.Warn(ex, "Unable to add queue item");
                response.Status = HttpStatusCode.NotFound;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "Unable to add queue item"));
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to add queue item");
                response.Status = HttpStatusCode.InternalServerError;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to add queue item"));
            }
            return(response);
        }
        /// <summary>
        /// This method is used to check in into the helpdesk system
        /// </summary>
        /// <param name="request">The request containing the specified UnitID</param>
        /// <returns>A response indicating success or failure</returns>
        public CheckInResponse CheckIn(CheckInRequest request)
        {
            CheckInResponse response = new CheckInResponse();

            try
            {
                response = (CheckInResponse)request.CheckValidation(response);

                if (response.Status == HttpStatusCode.BadRequest)
                {
                    return(response);
                }

                StudentFacade studentFacade = new StudentFacade();

                if (!request.StudentID.HasValue)
                {
                    if (studentFacade.GetStudentByNickname(request.Nickname).Status != HttpStatusCode.NotFound)
                    {
                        response.Status = HttpStatusCode.BadRequest;
                        return(response);
                    }

                    AddStudentRequest addStudentRequest = new AddStudentRequest()
                    {
                        SID      = request.SID,
                        Nickname = request.Nickname
                    };

                    AddStudentResponse addStudentResponse = studentFacade.AddStudentNickname(addStudentRequest);

                    request.StudentID = addStudentResponse.StudentID;
                }

                using (helpdesksystemContext context = new helpdesksystemContext())
                {
                    if (context.Nicknames.FirstOrDefault(n => n.StudentId == request.StudentID) == null)
                    {
                        throw new NotFoundException("No student found for id " + request.StudentID);
                    }
                }

                CheckInDataLayer dataLayer = new CheckInDataLayer();
                int checkInID = dataLayer.CheckIn(request);

                response.StudentID = request.StudentID.Value;
                response.CheckInID = checkInID;
                response.Status    = HttpStatusCode.OK;
            }
            catch (NotFoundException ex)
            {
                s_logger.Warn(ex, "No student found for id " + request.SID);
                response.Status = HttpStatusCode.NotFound;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "No student found for id " + request.SID));
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to check in");
                response.Status = HttpStatusCode.InternalServerError;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to check in"));
            }
            return(response);
        }