Ejemplo n.º 1
0
        /*
         *  POST http://localhost:4338/api/SpreadSheet/payment/update
         *
         *  request:
         *  {
         *      "rowId": "1234",
         *      "invoice": "1234A",
         *      "status": "SUCCESS",
         *      "amount": 200
         *  }
         */
        public int UpdatePaymentData([FromBody] PaymentDataRequest request)
        {
            var service = SpreadSheetServiceFactory.Produce();

            var rowNumbers = SpreadSheetServiceHelper.FindRowNumbers(service, request.RowId);

            var values = new List <object> {
                request.Status, request.Invoice, request.Amount
            };

            var result = 0;

            foreach (var rowNumber in rowNumbers)
            {
                var apiUpdateRequest = service.Spreadsheets.Values.Update(new ValueRange
                {
                    MajorDimension = "ROWS", // COLUMNS/ ROWS
                    Values         = new List <IList <object> > {
                        values
                    }
                }, AppConfig.SpreadSheetId, string.Format("Sheet1!I{0}", rowNumber)); // I2 = starting point

                apiUpdateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW;
                var apiUpdateResponse = apiUpdateRequest.Execute();
                result += apiUpdateResponse.UpdatedColumns.HasValue? apiUpdateResponse.UpdatedColumns.Value : 0;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /*
         *  GET http://localhost:4338/api/SpreadSheet/34567/tickets
         *
         *  response:
         *  {
         *          "rowId": 31519,
         *          "ticketA": {
         *                  "count": 1,
         *                  "participants": [
         *                          {
         *                                  "rowId": 31519,
         *                                  "pId": 43239,
         *                                  "name": "-",
         *                                  "email": "-",
         *                                  "phone": "-",
         *                                  "jobTitle": "-",
         *                                  "company": "-",
         *                                  "ticket": "TicketA"
         *                          }
         *                  ]
         *          },
         *          "ticketB": {
         *                  "count": 2,
         *                  "participants": [
         *                          {
         *                                  "rowId": 31519,
         *                                  "pId": 24978,
         *                                  "name": "-",
         *                                  "email": "-",
         *                                  "phone": "-",
         *                                  "jobTitle": "-",
         *                                  "company": "-",
         *                                  "ticket": "TicketB"
         *                          }
         *                  ]
         *          },
         *          "ticketC": {
         *                  "count": 2,
         *                  "participants": [
         *                          {
         *                                  "rowId": 31519,
         *                                  "pId": 78304,
         *                                  "name": "-",
         *                                  "email": "-",
         *                                  "phone": "-",
         *                                  "jobTitle": "-",
         *                                  "company": "-",
         *                                  "ticket": "TicketC"
         *                          }
         *                  ]
         *          }
         *  }
         */
        public TicketsDataResponse GetTicketsData(int rowId)
        {
            var service = SpreadSheetServiceFactory.Produce();

            var rowsData = SpreadSheetServiceHelper.FindRows(service, rowId);

            if (rowsData == null)
            {
                return(null);
            }

            var response = new TicketsDataResponse {
                RowId   = rowId,
                TicketA = new TicketData(),
                TicketB = new TicketData(),
                TicketC = new TicketData()
            };

            foreach (var rowData in rowsData)
            {
                var participant = new ParticipantDataRequest
                {
                    RowId      = rowId,
                    pId        = Convert.ToInt32(rowData[11]),
                    Name       = rowData[12].ToString(),
                    Phone      = rowData[13].ToString(),
                    Email      = rowData[14].ToString(),
                    JobTitle   = rowData[15].ToString(),
                    Company    = rowData[16].ToString(),
                    TicketName = rowData[17].ToString()
                };

                switch (participant.TicketName.ToLower())
                {
                case "ticketa":
                    response.TicketA.Participants.Add(participant);
                    break;

                case "ticketb":
                    response.TicketB.Participants.Add(participant);
                    break;

                case "ticketc":
                    response.TicketC.Participants.Add(participant);
                    break;
                }
            }

            return(response);
        }
Ejemplo n.º 3
0
        /*
         *  POST http://localhost:4338/api/SpreadSheet/participant/update
         *
         *  request:
         *  {
         *      "rowId": 1234,
         *      "pId": 3344,
         *      "name": "Avi",
         *      "email" : "*****@*****.**",
         *      "phone":"054-5555555",
         *      "jobTitle": "Developer",
         *      "company": "Celcom",
         *      "ticket": "TicketA"
         *  }
         */
        public int UpdateParticipantData([FromBody] ParticipantDataRequest request)
        {
            var service = SpreadSheetServiceFactory.Produce();

            var rowNumber = SpreadSheetServiceHelper.FindParticipantRowNumber(service, request.RowId, request.pId);

            var values = new List <object> {
                request.Name, request.Phone, request.Email, request.JobTitle, request.Company
            };

            var apiUpdateRequest = service.Spreadsheets.Values.Update(new ValueRange
            {
                MajorDimension = "ROWS", // COLUMNS/ ROWS
                Values         = new List <IList <object> > {
                    values
                }
            }, AppConfig.SpreadSheetId, string.Format("Sheet1!M{0}", rowNumber)); // M2 = starting point

            apiUpdateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW;
            var apiUpdateResponse = apiUpdateRequest.Execute();

            return(apiUpdateResponse.UpdatedColumns.HasValue ? apiUpdateResponse.UpdatedColumns.Value : 0);
        }