Example #1
0
        // GET: api/Employee/5
        public async Task <Employee> Get(string id)
        {
            using (Client client = await CdsHelper.CreateClientAsync(this.Request))
            {
                DataRangeSkipClauseBuilder <CarPool.Web.Library.Employee> query = client.GetRelationalEntitySet <CarPool.Web.Library.Employee>()
                                                                                  .CreateQueryBuilder()
                                                                                  .Where(pc => pc.PrimaryId == id)
                                                                                  .Project(pc => pc
                                                                                           .SelectField(f => f.PrimaryId)
                                                                                           .SelectField(f => f.FullName)
                                                                                           .SelectField(f => f.HomeAddress)
                                                                                           .SelectField(f => f.WorkAddress)
                                                                                           .SelectField(f => f.PreferredArrivalTimeAtWork)
                                                                                           .SelectField(f => f.PreferredDepartureTimeFromWork)
                                                                                           .SelectField(f => f.Email)
                                                                                           .SelectField(f => f.Phone)
                                                                                           .SelectField(f => f.BusinessUnit)
                                                                                           .SelectField(f => f.HomeLatitude)
                                                                                           .SelectField(f => f.HomeLongitude)
                                                                                           .SelectField(f => f.WorkLatitude)
                                                                                           .SelectField(f => f.WorkLongitude)
                                                                                           );

                OperationResult <IReadOnlyList <CarPool.Web.Library.Employee> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                var employee = CDSEmployeeToAppEmployee(queryResult.Result.First());
                return(employee);
            }
        }
        // PUT: api/RideDetails/5
        public async Task Put(string id, [FromBody] RideDetails value)
        {
            using (var client = await CdsHelper.CreateClientAsync(this.Request))
            {
                var query = client.GetRelationalEntitySet <CarPool.Web.Library.RideShare>()
                            .CreateQueryBuilder()
                            .Where(pc => pc.PrimaryId == id)
                            .Project(pc => pc
                                     .SelectField(f => f.PrimaryId)
                                     .SelectField(f => f.ExpenseReportSubmitted)
                                     .SelectField(f => f.ExpenseReportApproved)
                                     .SelectField(f => f.Passenger1OnRide)
                                     .SelectField(f => f.Passenger2OnRide)
                                     .SelectField(f => f.Passenger3OnRide)
                                     .SelectField(f => f.Passenger4OnRide)
                                     .SelectField(f => f.RideCompleted)
                                     .SelectField(f => f.FinanceApprovalStatus)
                                     .SelectField(f => f.Passenger1Name)
                                     .SelectField(f => f.Passenger2Name)
                                     .SelectField(f => f.Passenger3Name)
                                     .SelectField(f => f.Passenger4Name)
                                     .SelectField(f => f.DistanceString)
                                     .SelectField(f => f.RideDateTime)
                                     .SelectField(f => f.DriverName)
                                     .SelectField(f => f.RouteDescription)
                                     .SelectField(f => f.DistanceString)
                                     .SelectField(f => f.Distance)
                                     );

                OperationResult <IReadOnlyList <CarPool.Web.Library.RideShare> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                var updateExecutor = client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional);
                var cdsItem        = queryResult.Result.First();
                var updateItem     = client.CreateRelationalFieldUpdates <CarPool.Web.Library.RideShare>();

                updateItem.Update(pc => pc.DriverName, value.Driver);
                updateItem.Update(pc => pc.Distance, Convert.ToDecimal(value.Distance));
                updateItem.Update(pc => pc.ExpenseReportSubmitted, value.EmployeeSubmissionStatus);
                updateItem.Update(pc => pc.RideDateTime, new DateTimeOffset(value.Date.ToUniversalTime()));
                updateItem.Update(pc => pc.FinanceApprovalStatus, value.FinanceApprovalStatus);
                updateItem.Update(pc => pc.ExpenseReportApproved, value.ManagerApprovalStatus);
                updateItem.Update(pc => pc.RouteDescription, value.Route);
                updateItem.Update(pc => pc.Passenger1Name, value.Rider1);
                updateItem.Update(pc => pc.Passenger1OnRide, value.Rider1Status);
                updateItem.Update(pc => pc.Passenger2Name, value.Rider2);
                updateItem.Update(pc => pc.Passenger2OnRide, value.Rider2Status);
                updateItem.Update(pc => pc.Passenger3Name, value.Rider3);
                updateItem.Update(pc => pc.Passenger3OnRide, value.Rider3Status);
                updateItem.Update(pc => pc.Passenger4Name, value.Rider4);
                updateItem.Update(pc => pc.Passenger4OnRide, value.Rider4Status);

                updateExecutor.Update(cdsItem, updateItem);
                await updateExecutor.ExecuteAsync();
            }
        }
Example #3
0
        // POST: api/Employee
        public async Task Post([FromBody] Employee value)
        {
            using (var client = await CdsHelper.CreateClientAsync(this.Request))
            {
                var cdsEmployee = AppEmployeeToCDSEmployee(value);

                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Insert(cdsEmployee)
                .ExecuteAsync();
            }
        }
        // POST: api/RideDetails
        public async Task Post([FromBody] RideDetails value)
        {
            using (var client = await CdsHelper.CreateClientAsync(this.Request))
            {
                var item = AppRideDetailsToCDSRideDetails(value);

                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Insert(item)
                .ExecuteAsync();
            }
        }
Example #5
0
        // PUT: api/Employee/5
        public async Task Put(string id, [FromBody] Employee value)
        {
            using (var client = await CdsHelper.CreateClientAsync(this.Request))
            {
                var query = client.GetRelationalEntitySet <CarPool.Web.Library.Employee>()
                            .CreateQueryBuilder()
                            .Where(pc => pc.PrimaryId == id)
                            .Project(pc => pc
                                     .SelectField(f => f.PrimaryId)
                                     .SelectField(f => f.FullName)
                                     .SelectField(f => f.HomeAddress)
                                     .SelectField(f => f.WorkAddress)
                                     .SelectField(f => f.PreferredArrivalTimeAtWork)
                                     .SelectField(f => f.PreferredDepartureTimeFromWork)
                                     .SelectField(f => f.Email)
                                     .SelectField(f => f.Phone)
                                     .SelectField(f => f.BusinessUnit)
                                     .SelectField(f => f.HomeLatitude)
                                     .SelectField(f => f.HomeLongitude)
                                     .SelectField(f => f.WorkLatitude)
                                     .SelectField(f => f.WorkLongitude)
                                     );

                OperationResult <IReadOnlyList <CarPool.Web.Library.Employee> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                var updateExecutor = client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional);
                var cdsEmployee    = queryResult.Result.First();
                var updateEmployee = client.CreateRelationalFieldUpdates <CarPool.Web.Library.Employee>();

                updateEmployee.Update(pc => pc.FullName, value.Name);
                updateEmployee.Update(pc => pc.HomeAddress, CreateNewAddressWithLine1(value.HomeAddress));
                updateEmployee.Update(pc => pc.WorkAddress, CreateNewAddressWithLine1(value.WorkAddress));
                updateEmployee.Update(pc => pc.PreferredArrivalTimeAtWork, new DateTimeOffset(value.Arrival.ToUniversalTime()));
                updateEmployee.Update(pc => pc.PreferredDepartureTimeFromWork, new DateTimeOffset(value.Departure.ToUniversalTime()));
                updateEmployee.Update(pc => pc.Email, value.Email);
                updateEmployee.Update(pc => pc.Phone, value.PhoneNo);
                //Not used in app -- updateEmployee.Update(pc => pc.BusinessUnit, value.BusinessUnit);
                updateEmployee.Update(pc => pc.HomeLatitude, Convert.ToDecimal(value.Latitude));
                updateEmployee.Update(pc => pc.HomeLongitude, Convert.ToDecimal(value.Longitude));
                updateEmployee.Update(pc => pc.WorkLatitude, Convert.ToDecimal(value.WorkLatitude));
                updateEmployee.Update(pc => pc.WorkLongitude, Convert.ToDecimal(value.WorkLongitude));

                updateExecutor.Update(cdsEmployee, updateEmployee);
                await updateExecutor.ExecuteAsync();
            }
        }
        // GET: api/RideDetails
        public async Task <IEnumerable <RideDetails> > Get()
        {
            using (Client client = await CdsHelper.CreateClientAsync(this.Request))
            {
                DataRangeSkipClauseBuilder <CarPool.Web.Library.RideShare> query = client.GetRelationalEntitySet <CarPool.Web.Library.RideShare>()
                                                                                   .CreateQueryBuilder()
                                                                                   .Project(pc => pc
                                                                                            .SelectField(f => f.PrimaryId)
                                                                                            .SelectField(f => f.ExpenseReportSubmitted)
                                                                                            .SelectField(f => f.ExpenseReportApproved)
                                                                                            .SelectField(f => f.Passenger1OnRide)
                                                                                            .SelectField(f => f.Passenger2OnRide)
                                                                                            .SelectField(f => f.Passenger3OnRide)
                                                                                            .SelectField(f => f.Passenger4OnRide)
                                                                                            .SelectField(f => f.RideCompleted)
                                                                                            .SelectField(f => f.FinanceApprovalStatus)
                                                                                            .SelectField(f => f.Passenger1Name)
                                                                                            .SelectField(f => f.Passenger2Name)
                                                                                            .SelectField(f => f.Passenger3Name)
                                                                                            .SelectField(f => f.Passenger4Name)
                                                                                            .SelectField(f => f.DistanceString)
                                                                                            .SelectField(f => f.RideDateTime)
                                                                                            .SelectField(f => f.DriverName)
                                                                                            .SelectField(f => f.RouteDescription)
                                                                                            .SelectField(f => f.DistanceString)
                                                                                            .SelectField(f => f.Distance)
                                                                                            );

                OperationResult <IReadOnlyList <CarPool.Web.Library.RideShare> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                var results = new List <RideDetails>();
                foreach (var entry in queryResult.Result)
                {
                    results.Add(CDSRideDetailsToAppRideDetails(entry));
                }
                return(results);
            }
        }
Example #7
0
        // GET: api/Driver
        public async Task <IEnumerable <Driver> > Get()
        {
            using (Client client = await CdsHelper.CreateClientAsync(this.Request))
            {
                DataRangeSkipClauseBuilder <CarPool.Web.Library.Driver> query = client.GetRelationalEntitySet <CarPool.Web.Library.Driver>()
                                                                                .CreateQueryBuilder()
                                                                                .Project(pc => pc
                                                                                         .SelectField(f => f.PrimaryId)
                                                                                         .SelectField(f => f.RouteTitle)
                                                                                         .SelectField(f => f.AverageMiles)
                                                                                         .SelectField(f => f.RatePerMile)
                                                                                         .SelectField(f => f.Name)
                                                                                         .SelectField(f => f.DisplayName)
                                                                                         .SelectField(f => f.Schedule)
                                                                                         .SelectField(f => f.HomeLatitude)
                                                                                         .SelectField(f => f.HomeLongitude)
                                                                                         .SelectField(f => f.Arrival)
                                                                                         .SelectField(f => f.Departure)
                                                                                         .SelectField(f => f.Rider1Name)
                                                                                         .SelectField(f => f.Rider1Status)
                                                                                         .SelectField(f => f.Rider2Name)
                                                                                         .SelectField(f => f.Rider2Status)
                                                                                         .SelectField(f => f.Rider3Name)
                                                                                         .SelectField(f => f.Rider3Status)
                                                                                         .SelectField(f => f.Rider4Name)
                                                                                         .SelectField(f => f.Rider4Status)
                                                                                         );

                OperationResult <IReadOnlyList <CarPool.Web.Library.Driver> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                var results = new List <Driver>();
                foreach (var entry in queryResult.Result)
                {
                    results.Add(CDSDriverToAppDriver(entry));
                }
                return(results);
            }
        }
Example #8
0
        // GET: api/Employee
        public async Task <IEnumerable <Employee> > Get()
        {
            //Get CDS SDK reference ready to communicate with CDS environment
            using (Client client = await CdsHelper.CreateClientAsync(this.Request))
            {
                //Build query
                DataRangeSkipClauseBuilder <CarPool.Web.Library.Employee> query = client.GetRelationalEntitySet <CarPool.Web.Library.Employee>()
                                                                                  .CreateQueryBuilder()
                                                                                  .Project(pc => pc
                                                                                           .SelectField(f => f.PrimaryId)
                                                                                           .SelectField(f => f.FullName)
                                                                                           .SelectField(f => f.HomeAddress)
                                                                                           .SelectField(f => f.WorkAddress)
                                                                                           .SelectField(f => f.PreferredArrivalTimeAtWork)
                                                                                           .SelectField(f => f.PreferredDepartureTimeFromWork)
                                                                                           .SelectField(f => f.Email)
                                                                                           .SelectField(f => f.Phone)
                                                                                           .SelectField(f => f.BusinessUnit)
                                                                                           .SelectField(f => f.HomeLatitude)
                                                                                           .SelectField(f => f.HomeLongitude)
                                                                                           .SelectField(f => f.WorkLatitude)
                                                                                           .SelectField(f => f.WorkLongitude)
                                                                                           );

                //Execute query
                OperationResult <IReadOnlyList <CarPool.Web.Library.Employee> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                //Transform query results
                var employees = new List <Employee>();
                foreach (var entry in queryResult.Result)
                {
                    employees.Add(CDSEmployeeToAppEmployee(entry));
                }
                return(employees);
            }
        }
Example #9
0
        // DELETE: api/Employee/5
        public async Task Delete(string id)
        {
            using (var client = await CdsHelper.CreateClientAsync(this.Request))
            {
                var query = client.GetRelationalEntitySet <CarPool.Web.Library.Employee>()
                            .CreateQueryBuilder()
                            .Where(pc => pc.PrimaryId == id)
                            .Project(pc => pc.SelectField(f => f.PrimaryId).SelectField(f => f.FullName));

                OperationResult <IReadOnlyList <CarPool.Web.Library.Employee> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                var deleteExecutor = client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional);
                foreach (var entry in queryResult.Result)
                {
                    deleteExecutor.DeleteWithoutConcurrencyCheck(entry);
                }
                await deleteExecutor.ExecuteAsync();
            }
        }
Example #10
0
        // PUT: api/Driver/5
        public async Task Put(string id, [FromBody] Driver value)
        {
            using (var client = await CdsHelper.CreateClientAsync(this.Request))
            {
                var query = client.GetRelationalEntitySet <CarPool.Web.Library.Driver>()
                            .CreateQueryBuilder()
                            .Where(pc => pc.PrimaryId == id)
                            .Project(pc => pc
                                     .SelectField(f => f.PrimaryId)
                                     .SelectField(f => f.RouteTitle)
                                     .SelectField(f => f.AverageMiles)
                                     .SelectField(f => f.RatePerMile)
                                     .SelectField(f => f.Name)
                                     .SelectField(f => f.DisplayName)
                                     .SelectField(f => f.Schedule)
                                     .SelectField(f => f.HomeLatitude)
                                     .SelectField(f => f.HomeLongitude)
                                     .SelectField(f => f.Arrival)
                                     .SelectField(f => f.Departure)
                                     .SelectField(f => f.Rider1Name)
                                     .SelectField(f => f.Rider1Status)
                                     .SelectField(f => f.Rider2Name)
                                     .SelectField(f => f.Rider2Status)
                                     .SelectField(f => f.Rider3Name)
                                     .SelectField(f => f.Rider3Status)
                                     .SelectField(f => f.Rider4Name)
                                     .SelectField(f => f.Rider4Status)
                                     );

                OperationResult <IReadOnlyList <CarPool.Web.Library.Driver> > queryResult = null;
                await client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional)
                .Query(query, out queryResult)
                .ExecuteAsync();

                var updateExecutor = client.CreateRelationalBatchExecuter(RelationalBatchExecutionMode.Transactional);
                var cdsItem        = queryResult.Result.First();
                var updateItem     = client.CreateRelationalFieldUpdates <CarPool.Web.Library.Driver>();

                updateItem.Update(pc => pc.Name, value.Name);
                updateItem.Update(pc => pc.Arrival, new DateTimeOffset(value.Arrival.ToUniversalTime()));
                updateItem.Update(pc => pc.Departure, new DateTimeOffset(value.Departure.ToUniversalTime()));
                updateItem.Update(pc => pc.AverageMiles, Convert.ToDecimal(value.AverageMiles));
                updateItem.Update(pc => pc.DisplayName, value.DisplayName);
                updateItem.Update(pc => pc.HomeLatitude, value.Latitude.HasValue ? Convert.ToDecimal(value.Latitude) : 0);
                updateItem.Update(pc => pc.HomeLongitude, value.Longitude.HasValue ? Convert.ToDecimal(value.Longitude) : 0);

                //Handle RatePerMile currency
                Microsoft.CommonDataService.Currency currency = new Microsoft.CommonDataService.Currency();
                currency.Amount = !String.IsNullOrEmpty(value.RatePerMile) ? Convert.ToDecimal(value.RatePerMile) : 0;
                updateItem.Update(pc => pc.RatePerMile, currency);

                updateItem.Update(pc => pc.Rider1Name, value.Rider1);
                updateItem.Update(pc => pc.Rider1Status, value.Rider1Status);
                updateItem.Update(pc => pc.Rider2Name, value.Rider2);
                updateItem.Update(pc => pc.Rider2Status, value.Rider2Status);
                updateItem.Update(pc => pc.Rider3Name, value.Rider3);
                updateItem.Update(pc => pc.Rider3Status, value.Rider3Status);
                updateItem.Update(pc => pc.Rider4Name, value.Rider4);
                updateItem.Update(pc => pc.Rider4Status, value.Rider4Status);
                updateItem.Update(pc => pc.Schedule, value.Schedule);

                updateExecutor.Update(cdsItem, updateItem);
                await updateExecutor.ExecuteAsync();
            }
        }