Example #1
0
        public ActionResult <Response> SetNotificationsRead(ReadNotificationsRequest jsonNotificationIDs)
        {
            try
            {
                //Call the data access layer to update the notification records
                Response response = new PlayerDAL().SetNotificationsRead(jsonNotificationIDs);

                //If the response was successful update the client's notifications list
                if (response.IsSuccessful())
                {
                    new HubInterface(_hubContext).UpdateNotificationsRead(Convert.ToInt32(jsonNotificationIDs.PlayerID));
                }

                return(response);
            }
            //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));
            }
        }
        /// <summary>
        /// Marks a players notifications as read.
        /// </summary>
        /// <param name="jsonNotificationIDs">The ID's of notifications to set as read.</param>
        /// <returns>Success or error.</returns>
        public Response SetNotificationsRead(ReadNotificationsRequest jsonNotificationIDs)
        {
            StoredProcedure = "usp_SetNotificationsRead";
            try
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("notificationID");
                for (int i = 0; i < jsonNotificationIDs.NotificationArray.Length; i++)
                {
                    dt.Rows.Add(jsonNotificationIDs.NotificationArray[i]);
                }

                //Create the connection and command for the stored procedure
                using (Connection = new SqlConnection(ConnectionString))
                {
                    using (Command = new SqlCommand(StoredProcedure, Connection))
                    {
                        //Add the procedure input and output params
                        AddParam("playerID", jsonNotificationIDs.PlayerID);
                        AddParam("udtNotifs", dt);
                        AddDefaultParams();

                        //Perform the procedure and get the result
                        Run();

                        //Format the results into a response object
                        ReadDefaultParams();
                        return(new Response(ErrorMSG, Result));
                    }
                }
            }

            //A database exception was thrown, return an error response
            catch
            {
                return(Response.DatabaseErrorResponse());
            }
        }