public ActionResult CheckOut(User_Transportation_Log trans) { if (ModelState.IsValid) { try { var userId = transportationContext.Users.Where(u => u.BannerId == trans.BannerId).Select(i => i.UserId).FirstOrDefault(); var vehicleId = transportationContext.Vehicles.Where(v => v.VehicleName == trans.VehicleName).Select(i => i.VehicleId).FirstOrDefault(); var keyId = transportationContext.Keys.Where(k => k.KeyName == trans.KeyName).Select(i => i.KeyId).FirstOrDefault(); var gasCardId = transportationContext.GasCards.Where(g => g.GasCardName == trans.GasCardName).Select(i => i.GasCardId).FirstOrDefault(); if (userId != 0 && vehicleId != 0 && keyId != 0 && gasCardId != 0) { SignOut signLog = new SignOut(); signLog.UserId = userId; signLog.VehicleId = vehicleId; signLog.KeyId = keyId; signLog.Destination = trans.Destination; signLog.GasCardId = gasCardId; signLog.CheckOutTime = DateTime.Now; signLog.ActivityTime = DateTime.Now; transportationContext.SignOuts.Add(signLog); transportationContext.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(new HttpStatusCodeResult(Response.StatusCode = 400)); } } return(View()); }
public ActionResult CreateUser(Admin_Create_User CUser) { if (ModelState.IsValid) { try { var departmentId = transportationContext.Departments.Where(d => d.DepartmentName == CUser.DepartmentName).Select(i => i.DepartmentId).FirstOrDefault(); var statusId = transportationContext.UserStatuses.Where(s => s.StatusName == CUser.StatusName).Select(i => i.StatusId).FirstOrDefault(); if (departmentId != 0 && statusId != 0) { User user = new User(); user.BannerId = CUser.BannerId; user.FirstName = CUser.FirstName; user.LastName = CUser.LastName; user.DepartmentId = departmentId; user.StatusId = statusId; transportationContext.Users.Add(user); transportationContext.SaveChanges(); return(RedirectToAction("index")); } return(new HttpStatusCodeResult(Response.StatusCode = 400)); } catch { return(new HttpStatusCodeResult(Response.StatusCode = 400)); } } return(View()); }
public ActionResult CreateGasCard(Admin_Create_GasCard CGasCard) { if (ModelState.IsValid) { try { var statusId = transportationContext.GasCardStatuses.Where(Gs => Gs.StatusName == CGasCard.StatusName).Select(i => i.StatusId).FirstOrDefault(); if (statusId != 0) { //instantiate object GasCard gasCard = new GasCard(); //set gasCard.GasCardName = CGasCard.GasCardName; gasCard.GasCardNum = CGasCard.GasCardNum; gasCard.GasCardPin = CGasCard.GasCardPin; gasCard.StatusId = statusId; //add transportationContext.GasCards.Add(gasCard); //save transportationContext.SaveChanges(); return(RedirectToAction("Index")); } return(new HttpStatusCodeResult(Response.StatusCode = 400)); } catch { return(new HttpStatusCodeResult(Response.StatusCode = 400)); } } return(View()); }
public ActionResult DeleteUser(int?id, User Trash) { try { User user = new User(); if (ModelState.IsValid) { if (id == null) { return(new HttpStatusCodeResult(Response.StatusCode = 400)); } user = transportationContext.Users.Find(id); if (user == null) { return(HttpNotFound()); } transportationContext.Users.Remove(user); transportationContext.SaveChanges(); } return(View(user)); } catch { return(View()); } }
public ActionResult EditUser(User user) { try { if (ModelState.IsValid) { var departmentId = transportationContext.Departments.Where(d => d.DepartmentName == user.Department.DepartmentName).Select(i => i.DepartmentId).FirstOrDefault(); if (departmentId != 0) { user.DepartmentId = departmentId; user.Department.DepartmentId = departmentId; transportationContext.Entry(user).State = System.Data.Entity.EntityState.Modified; transportationContext.SaveChanges(); } return(RedirectToAction("Index", "Admin")); } return(View(user)); } catch { return(View()); } }
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()); }