Exemplo n.º 1
0
        public ActionResult <Response> Upload(PhotoUploadRequest request)
        {
            try
            {
                //Build the photo object
                Photo uploadedPhoto = new Photo(request.latitude, request.longitude, request.imgUrl, request.takenByID, request.photoOfID);

                //Get the player object from the database
                Response <Player> getPlayerResponse = new PlayerDAL().GetPlayerByID(uploadedPhoto.TakenByPlayerID);
                if (!getPlayerResponse.IsSuccessful())
                {
                    return(new Response(getPlayerResponse.ErrorMessage, getPlayerResponse.ErrorCode));
                }

                Response <Photo> response;

                //Call the BR Upload business logic if the player is a BR player
                if (getPlayerResponse.Data.IsBRPlayer())
                {
                    response = new PhotoDAL().SavePhoto(uploadedPhoto, true);
                }

                //Otherwise, call the CORE business logic
                else
                {
                    response = new PhotoDAL().SavePhoto(uploadedPhoto, false);
                }

                //If the response is successful we want to send live updates to clients and
                //email or text message notifications to not connected players
                if (response.IsSuccessful())
                {
                    HubInterface hubInterface = new HubInterface(_hubContext);
                    hubInterface.UpdatePhotoUploaded(response.Data);
                    ScheduledTasks.ScheduleCheckPhotoVotingCompleted(response.Data, hubInterface);
                }
                return(new Response(response.ErrorMessage, response.ErrorCode));
            }
            //Catch any error associated with invalid model data
            catch (InvalidModelException e)
            {
                return(new Response(e.Msg, e.Code));
            }
            //Catch any unhandled / unexpected server errrors
            catch
            {
                return(StatusCode(500));
            }
        }