public ActionResult NewRequest(TransportationRequest_View transRequest)//Drivers[] drivers
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Grabs current logged on user ID as they will be the requester
                    var RequesterId = transportationContext.Users.Where(u => u.BannerId == transRequest.BannerId).Select(i => i.UserId).FirstOrDefault();

                    if (RequesterId != null)
                    {
                        TransportationRequest newRequest = new TransportationRequest();
                        newRequest.RequesterUserId = RequesterId;
                        newRequest.LeaveDate       = transRequest.LeaveDate.GetValueOrDefault();
                        newRequest.LeaveTime       = transRequest.LeaveTime.GetValueOrDefault();
                        newRequest.ReturnDate      = transRequest.ReturnDate.GetValueOrDefault();
                        newRequest.ReturnTime      = transRequest.ReturnTime.GetValueOrDefault();
                        newRequest.Destination     = transRequest.Destination;
                        newRequest.TripPurpose     = transRequest.TripPurpose;
                        newRequest.NumOfStudents   = transRequest.NumOfStudents.GetValueOrDefault();

                        /* Testing default values */
                        newRequest.RequesterUserId = 1;
                        newRequest.LeaveDate       = DateTime.Parse("7/1/2017");
                        newRequest.LeaveTime       = TimeSpan.Parse("5:15");
                        newRequest.ReturnDate      = DateTime.Parse("7/5/2017");
                        newRequest.ReturnTime      = TimeSpan.Parse("18:35");
                        newRequest.Destination     = "LA";
                        newRequest.TripPurpose     = "Pancakes";
                        newRequest.NumOfStudents   = 4;

                        //Create Empty Int Object
                        var transReqId = new ObjectParameter("TranReqId", typeof(int));
                        //Call Precedure and give transReqId a value
                        transportationContext.p_TransReq_Add(newRequest.RequesterUserId, newRequest.LeaveDate, newRequest.LeaveTime, newRequest.ReturnDate, newRequest.ReturnTime, newRequest.Destination, newRequest.TripPurpose, newRequest.NumOfStudents, transReqId);

                        //Drivers _Drivers = new Drivers();
                        //_Drivers.DriverUserId = 1;
                        //_Drivers.NeedGasCard = false;
                        //_Drivers.TransReqId = Convert.ToInt16(transReqId.Value);
                        //_Drivers.VehicleAddonId = 1;
                        //_Drivers.VehicleTypeId = 1;
                        //for (int i = 0; i<drivers.Length; i++) {

                        //    drivers[i].DriverUserId = 1;

                        //}


                        if (transReqId != null)
                        {
                            //foreach (driver in array)
                            //{
                            //    insert into db
                            //}
                        }

                        return(RedirectToAction("RequestConfirmation"));
                    }


                    // Will require a foreach loop to grab all drivers listed on request
                    //var DriverId = transportationContext.Users.Where(u => u.UserId == transRequest.UserId).Select(i => i.UserId).FirstOrDefault();

                    // Will require a foreach loop to grab all passangers listed on the request
                    //var PassangerId = transportationContext.Users.Where(u => u.UserId == transRequest.UserId).Select(i => i.UserId).FirstOrDefault();

                    // Add all drivers to DriverGroup Table
                    //foreach ( /* Driver listed on form (may need to make an array) */)
                    //{
                    //    DriverGroup Driver = new DriverGroup();
                    //    Driver.RequestId = 0/*Transportation Request primary key*/;
                    //    Driver.UserId = transportationContext.Users.Where(u => u.UserId == 0/*Current Driver Id*/).Select(i => i.UserId).FirstOrDefault();
                    //    if (true /*Driver requires a vehicle*/)
                    //    {
                    //        //Driver.VehicleType
                    //    }
                    //    transportationContext.DriverGroups.Add(Driver);
                    //}
                }
                catch
                {
                    return(new HttpStatusCodeResult(Response.StatusCode = 400));
                }
            }
            return(View());
        }
Пример #2
0
        public ActionResult NewRequest(TransportationRequest_View_DemoForSymposium transRequest)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Grabs current logged on user ID as they will be the requester
                    //Note: This Lambda function is using the logged in user as the requester so if html is edited the validation is still correct
                    var RequesterId = transportationContext.Users.Where(u => u.BannerId == _LoggedInUser.userInfo.EmployeeId.Substring(1)).Select(i => i.UserId).FirstOrDefault();

                    if (RequesterId != null)
                    {
                        TransportationRequest newRequest = new TransportationRequest();
                        newRequest.RequesterUserId = RequesterId;
                        newRequest.LeaveDate       = transRequest.LeaveDate.GetValueOrDefault();
                        newRequest.LeaveTime       = transRequest.LeaveTime.GetValueOrDefault();
                        newRequest.ReturnDate      = transRequest.ReturnDate.GetValueOrDefault();
                        newRequest.ReturnTime      = transRequest.ReturnTime.GetValueOrDefault();
                        newRequest.Destination     = transRequest.Destination;
                        newRequest.TripPurpose     = transRequest.TripPurpose;
                        newRequest.NumOfStudents   = transRequest.NumOfStudents.GetValueOrDefault();

                        //Create Empty Int Object
                        var transReqId = new ObjectParameter("TranReqId", typeof(int));
                        //Save Request and Get transportation request Id
                        transportationContext.p_TransReq_Add(newRequest.RequesterUserId, newRequest.LeaveDate, newRequest.LeaveTime, newRequest.ReturnDate, newRequest.ReturnTime, newRequest.Destination, newRequest.TripPurpose, newRequest.NumOfStudents, transReqId);

                        //Save to Driver Group Table
                        DriverGroup driverGroup = new DriverGroup();
                        driverGroup.NeedGasCard    = transRequest.NeedGasCard.GetValueOrDefault();
                        driverGroup.TranRequestId  = Convert.ToInt16(transReqId.Value);
                        driverGroup.UserId         = transRequest.UserId;
                        driverGroup.VehicleAddOnId = transRequest.VehicleAddOnId;
                        driverGroup.VehicleTypeId  = transRequest.VehicleTypeId;

                        //Add new driver associated with request
                        transportationContext.DriverGroups.Add(driverGroup);
                        //save
                        transportationContext.SaveChanges();

                        return(RedirectToAction("RequestConfirmation"));
                    }

                    // Will require a foreach loop to grab all drivers listed on request
                    //var DriverId = transportationContext.Users.Where(u => u.UserId == transRequest.UserId).Select(i => i.UserId).FirstOrDefault();

                    // Will require a foreach loop to grab all passangers listed on the request
                    //var PassangerId = transportationContext.Users.Where(u => u.UserId == transRequest.UserId).Select(i => i.UserId).FirstOrDefault();

                    // Add all drivers to DriverGroup Table
                    //foreach ( /* Driver listed on form (may need to make an array) */)
                    //{
                    //    DriverGroup Driver = new DriverGroup();
                    //    Driver.RequestId = 0/*Transportation Request primary key*/;
                    //    Driver.UserId = transportationContext.Users.Where(u => u.UserId == 0/*Current Driver Id*/).Select(i => i.UserId).FirstOrDefault();
                    //    if (true /*Driver requires a vehicle*/)
                    //    {
                    //        //Driver.VehicleType
                    //    }
                    //    transportationContext.DriverGroups.Add(Driver);
                    //}
                }
                catch
                {
                    return(new HttpStatusCodeResult(Response.StatusCode = 400));
                }
            }
            return(View());
        }