public ActionResult infoBike(int bikeID)
        {
            if (!authorize()) { return new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized); }
            var dbBike = context.Bike.Find(bikeID);
            var model = new ViewModels.Admin.AdminBikeDetailsVM
            {
                Id = bikeID,
                IsArchived = dbBike.isArchived,
                IsAvailable = dbBike.isAvailable(),
                Name = dbBike.bikeName,
                Number = dbBike.bikeNumber,
                LastBorrowed = dbBike.lastCheckedOut
            };
            if (dbBike.onInspectionHold) { model.Notes += "On inspection hold. "; }
            if (dbBike.onMaintenanceHold) { model.Notes += "On maintenance hold. "; }
            if (dbBike.lastCheckedOut.Year < 2014) //necessary because of messy db model
            {
                model.LastBorrowed = null;
                model.LastCheckedOutTo = null;
            }
            try
            {
                int lastUserId = context.CheckOut.Where(b => b.bike == bikeID).OrderByDescending(d => d.timeOut).First().rider;
                model.LastCheckedOutTo = context.BikeUser.Find(lastUserId).userName;
            }
            catch
            {
                model.LastCheckedOutTo = null;
            }

            model.CountOfRentals = context.CheckOut.Where(b => b.bike == bikeID).Count();
            model.Inspections = new List<ViewModels.Admin.AdminBikeDetailsVM.inspection>();
            context.Inspection.Where(b => b.bikeId == bikeID).ToList().ForEach(spec => {
                model.Inspections.Add(new ViewModels.Admin.AdminBikeDetailsVM.inspection {
                    Comment = spec.comment, Performed = spec.datePerformed, Passed = spec.isPassed
                });
            });
            model.Inspections =  model.Inspections.OrderByDescending(d => d.Performed).ToList();

            model.Maintenance = new List<ViewModels.Admin.AdminBikeDetailsVM.maintenance>();
            context.MaintenanceEvent.Where(b => b.bikeId == bikeID).ToList().ForEach(maint => {
                model.Maintenance.Add(new ViewModels.Admin.AdminBikeDetailsVM.maintenance { Date = maint.timeAdded, Resolved = maint.timeResolved.HasValue, Title = maint.title });
            });

            model.Maintenance = model.Maintenance.OrderByDescending(d => d.Date).ToList();

            model.CountOfInspections = model.Inspections.Count();
            model.CountOfMaintenance = model.Maintenance.Count();

            if (dbBike.bikeRackId != null)
            {
                model.RackLastSeen = context.BikeRack.Find(dbBike.bikeRackId).name;
            }
            else
            {
                model.RackLastSeen = "none";
            }

            return View(model);
        }
예제 #2
0
        public ActionResult infoBike(int bikeID)
        {
            if (!authorize())
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized));
            }
            var dbBike = context.Bike.Find(bikeID);
            var model  = new ViewModels.Admin.AdminBikeDetailsVM
            {
                Id           = bikeID,
                IsArchived   = dbBike.isArchived,
                IsAvailable  = dbBike.isAvailable(),
                Name         = dbBike.bikeName,
                Number       = dbBike.bikeNumber,
                LastBorrowed = dbBike.lastCheckedOut
            };

            if (dbBike.onInspectionHold)
            {
                model.Notes += "On inspection hold. ";
            }
            if (dbBike.onMaintenanceHold)
            {
                model.Notes += "On maintenance hold. ";
            }
            if (dbBike.lastCheckedOut.Year < 2014) //necessary because of messy db model
            {
                model.LastBorrowed     = null;
                model.LastCheckedOutTo = null;
            }
            try
            {
                int lastUserId = context.CheckOut.Where(b => b.bike == bikeID).OrderByDescending(d => d.timeOut).First().rider;
                model.LastCheckedOutTo = context.BikeUser.Find(lastUserId).userName;
            }
            catch
            {
                model.LastCheckedOutTo = null;
            }


            model.CountOfRentals = context.CheckOut.Where(b => b.bike == bikeID).Count();
            model.Inspections    = new List <ViewModels.Admin.AdminBikeDetailsVM.inspection>();
            context.Inspection.Where(b => b.bikeId == bikeID).ToList().ForEach(spec => {
                model.Inspections.Add(new ViewModels.Admin.AdminBikeDetailsVM.inspection {
                    Comment = spec.comment, Performed = spec.datePerformed, Passed = spec.isPassed
                });
            });
            model.Inspections = model.Inspections.OrderByDescending(d => d.Performed).ToList();

            model.Maintenance = new List <ViewModels.Admin.AdminBikeDetailsVM.maintenance>();
            context.MaintenanceEvent.Where(b => b.bikeId == bikeID).ToList().ForEach(maint => {
                model.Maintenance.Add(new ViewModels.Admin.AdminBikeDetailsVM.maintenance {
                    Date = maint.timeAdded, Resolved = maint.timeResolved.HasValue, Title = maint.title
                });
            });

            model.Maintenance = model.Maintenance.OrderByDescending(d => d.Date).ToList();

            model.CountOfInspections = model.Inspections.Count();
            model.CountOfMaintenance = model.Maintenance.Count();

            if (dbBike.bikeRackId != null)
            {
                model.RackLastSeen = context.BikeRack.Find(dbBike.bikeRackId).name;
            }
            else
            {
                model.RackLastSeen = "none";
            }


            return(View(model));
        }