Beispiel #1
0
        public ActionResult Create([Bind(Include = "RateTableID,BeatID,CurrentMonthRate,p100,p150,p200,p250,p300,p350,p400,p450,p500,p550,p600,p650,p700,p750,p800")] MTCRateTable mTCRateTable, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                mTCRateTable.BeatID      = new Guid(form["Beats"].ToString());
                mTCRateTable.RateTableID = Guid.NewGuid();
                _db.MTCRateTables.Add(mTCRateTable);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Beat = new SelectList(_db.BeatDatas.OrderBy(b => b.BeatName), "ID", "BeatName");
            return(View(mTCRateTable));
        }
Beispiel #2
0
        public ActionResult Save([Bind(Include = "FleetVehicleID,ContractorID,ProgramStartDate,FleetNumber,VehicleType,VehicleYear,VehicleMake,VehicleModel,VIN,LicensePlate,RegistrationExpireDate,InsuranceExpireDate,LastCHPInspection,Comments,ProgramEndDate,FAW,RAW,RAWR,GVW,GVWR,Wheelbase,Overhang,MAXTW,MAXTWCALCDATE,FuelType,VehicleNumber,IPAddress,TAIP,AgreementNumber,IsBackup")] FleetVehicle fleetVehicle)
        {
            if (fleetVehicle.FleetVehicleID != null && fleetVehicle.FleetVehicleID != Guid.Empty)
            {
                db.Entry(fleetVehicle).State = EntityState.Modified;
            }
            else
            {
                fleetVehicle.FleetVehicleID = Guid.NewGuid();
                db.FleetVehicles.Add(fleetVehicle);
            }

            db.SaveChanges();

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public async Task <ActionResult> Edit([Bind(Include = "VarID,VarName,VarValue,Description,Units,IsMTCAlarm,FriendlyVarName")] Var var)
        {
            if (ModelState.IsValid)
            {
                db.Entry(var).State = EntityState.Modified;
                db.SaveChanges();

                using (var service = new TowTruckServiceClient())
                {
                    service.UpdateVar(var.VarName, var.VarValue);
                }

                //Var dbVar = db.Vars.Find(var.VarID);
                //if (dbVar != null)
                //{
                //    dbVar.FriendlyVarName = var.FriendlyVarName;
                //    dbVar.Description = var.Description;
                //    dbVar.Units = var.Units;
                //    dbVar.IsMTCAlarm = var.IsMTCAlarm;
                //    db.Entry(dbVar).State = EntityState.Modified;
                //    await db.SaveChangesAsync();
                //}

                return(RedirectToAction("Index"));
            }
            return(View(var));
        }
Beispiel #4
0
        public ActionResult RemoveSchedule(Guid id)
        {
            using (MTCDBEntities db = new MTCDBEntities())
            {
                var response = new TransactionResult();
                try
                {
                    BeatSchedule bs = db.BeatSchedules.Find(id);
                    if (bs != null)
                    {
                        db.BeatBeatSchedules.RemoveRange(db.BeatBeatSchedules.Where(p => p.BeatScheduleID == bs.BeatScheduleID));
                        db.BeatSchedules.Remove(bs);
                        db.SaveChanges();
                    }

                    response.HasError = false;
                    response.Message  = String.Empty;
                }
                catch (Exception ex)
                {
                    response.HasError = true;
                    response.Message  = ex.InnerException.Message;
                }

                return(Json(response, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #5
0
        public ActionResult SaveContract(Contract model)
        {
            var      isNew    = model.ContractID == Guid.Empty ? true : false;
            Contract contract = null;

            if (isNew)
            {
                contract            = new Contract();
                contract.ContractID = Guid.NewGuid();
            }
            else
            {
                contract = db.Contracts.Find(model.ContractID);
            }

            contract.AgreementNumber = model.AgreementNumber;
            contract.StartDate       = model.StartDate;
            contract.EndDate         = model.EndDate;
            contract.MaxObligation   = model.MaxObligation;
            contract.ContractorID    = model.ContractorID;
            contract.BeatId          = model.BeatId;

            if (isNew)
            {
                db.Contracts.Add(contract);
            }

            db.SaveChanges();

            return(Json(contract.ContractID, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public ActionResult Save(CHPOfficer chpOfficer, List <BeatViewModel> Beats)
        {
            var        isNew   = chpOfficer.Id == 0 ? true : false;
            CHPOfficer officer = null;

            if (isNew)
            {
                officer = new CHPOfficer();
            }
            else
            {
                officer = db.CHPOfficers.Find(chpOfficer.Id);
            }

            officer.BadgeID          = chpOfficer.BadgeID;
            officer.OfficerLastName  = chpOfficer.OfficerLastName;
            officer.OfficerFirstName = chpOfficer.OfficerFirstName;
            officer.Email            = chpOfficer.Email;
            officer.Phone            = chpOfficer.Phone;

            if (isNew)
            {
                db.CHPOfficers.Add(officer);
            }

            db.SaveChanges();

            if (db.CHPOfficerBeats.Any(p => p.CHPOfficerId == officer.Id))
            {
                db.CHPOfficerBeats.RemoveRange(db.CHPOfficerBeats.Where(p => p.CHPOfficerId == officer.Id).ToList());
            }

            if (Beats != null)
            {
                foreach (var beat in Beats)
                {
                    db.CHPOfficerBeats.Add(new CHPOfficerBeat
                    {
                        CHPOfficerId = officer.Id,
                        BeatId       = beat.BeatId
                    });
                }
            }
            db.SaveChanges();

            return(Json(officer.Id, JsonRequestBehavior.AllowGet));
        }
Beispiel #7
0
        public ActionResult Save([Bind(Include = "DriverID,ContractorID,LastName,FirstName,FSPIDNumber,ProgramStartDate,TrainingCompletionDate,DOB,LicenseExpirationDate,DL64ExpirationDate,MedicalCardExpirationDate,LastPullNoticeDate,DateAdded,UDF,Comments,ContractorEndDate,ProgramEndDate,ContractorStartDate,BeatID,Password,DL64Number,DriversLicenseNumber,AddedtoC3Database")] Driver driver)
        {
            if (driver.DriverID != null && driver.DriverID != Guid.Empty)
            {
                db.Entry(driver).State = EntityState.Modified;
            }
            else
            {
                driver.DriverID  = Guid.NewGuid();
                driver.DateAdded = DateTime.Today;

                db.Drivers.Add(driver);
            }

            db.SaveChanges();

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Beispiel #8
0
 public ActionResult DeleteConfirmed(Guid id)
 {
     using (MTCDBEntities db = new MTCDBEntities())
     {
         BeatSchedule BeatSchedule = db.BeatSchedules.Find(id);
         db.BeatSchedules.Remove(BeatSchedule);
         db.SaveChanges();
         return(RedirectToAction("WeeklySchedule"));
     }
 }
Beispiel #9
0
        public ActionResult EditWeeklySchedule(BeatSchedule BeatSchedule)
        {
            using (MTCDBEntities db = new MTCDBEntities())
            {
                if (ModelState.IsValid)
                {
                    db.Entry(BeatSchedule).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("WeeklySchedule"));
                }
                return(View(BeatSchedule));
            }
        }
Beispiel #10
0
        public ActionResult Save(BeatCallSignsViewModel model)
        {
            using (var db = new MTCDBEntities())
            {
                var beat = db.BeatDatas.FirstOrDefault(b => b.ID == model.BeatId);
                if (beat == null)
                {
                    return(Json(model.BeatId, JsonRequestBehavior.AllowGet));
                }

                //beat.OnCallAreas = model.OnCallAreas;
                //beat.Freq = model.Freq;
                //beat.CHPArea = model.CHPArea;
                db.SaveChanges();


                if (db.MTCBeatsCallSigns.Any(p => p.BeatID.ToString() == model.BeatNumber) && model.CallSigns != null)
                {
                    db.MTCBeatsCallSigns.RemoveRange(db.MTCBeatsCallSigns.Where(p => p.BeatID.ToString() == model.BeatNumber).ToList());
                }

                if (model.CallSigns != null)
                {
                    foreach (var callSign in model.CallSigns)
                    {
                        db.MTCBeatsCallSigns.Add(new MTCBeatsCallSign
                        {
                            BeatID   = Convert.ToInt32(model.BeatNumber),
                            CallSign = callSign.CallSign
                        });
                    }
                }
                db.SaveChanges();

                return(Json(model.BeatId, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #11
0
        public ActionResult SaveSchedule(BeatScheduleViewModel model)
        {
            using (MTCDBEntities db = new MTCDBEntities())
            {
                BeatSchedule bs    = db.BeatSchedules.FirstOrDefault(p => p.BeatScheduleID == model.BeatScheduleId);
                var          isNew = false;
                if (bs == null)
                {
                    bs = new BeatSchedule();
                    bs.BeatScheduleID = Guid.NewGuid();
                    isNew             = true;
                }
                bs.ScheduleName = model.ScheduleName;
                bs.Sunday       = model.Sunday;
                bs.Monday       = model.Monday;
                bs.Tuesday      = model.Tuesday;
                bs.Wednesday    = model.Wednesday;
                bs.Thursday     = model.Thursday;
                bs.Friday       = model.Friday;
                bs.Saturday     = model.Saturday;
                bs.StartTime    = TimeSpan.Parse(model.StartTime);
                bs.EndTime      = TimeSpan.Parse(model.EndTime);

                if (isNew)
                {
                    db.BeatSchedules.Add(bs);

                    BeatBeatSchedule bbs = new BeatBeatSchedule();
                    bbs.BeatBeatScheduleID = Guid.NewGuid();
                    bbs.BeatScheduleID     = bs.BeatScheduleID;
                    bbs.BeatID             = model.BeatId;
                    bbs.NumberOfTrucks     = model.NumberOfTrucks;
                    db.BeatBeatSchedules.Add(bbs);
                }
                else
                {
                    BeatBeatSchedule bbs = db.BeatBeatSchedules.Where(b => b.BeatScheduleID == model.BeatScheduleId).Where(b => b.BeatID == model.BeatId).FirstOrDefault();
                    bbs.NumberOfTrucks = model.NumberOfTrucks;
                }

                db.SaveChanges();

                return(Json(true, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #12
0
        public ActionResult CreateWeeklySchedule(BeatSchedule BeatSchedule)
        {
            if (ModelState.IsValid)
            {
                using (MTCDBEntities db = new MTCDBEntities())
                {
                    if (!db.BeatSchedules.Any(p => p.ScheduleName == BeatSchedule.ScheduleName))
                    {
                        BeatSchedule.BeatScheduleID = Guid.NewGuid();
                        db.BeatSchedules.Add(BeatSchedule);
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("WeeklySchedule"));
            }

            return(View(BeatSchedule));
        }
Beispiel #13
0
        public ActionResult SaveContractor(ContractorDetailsViewModel model)
        {
            var        isNew      = model.ContractorId == Guid.Empty ? true : false;
            Contractor contractor = null;

            if (isNew)
            {
                contractor = new Contractor();
                contractor.ContractorID = Guid.NewGuid();
            }
            else
            {
                contractor = db.Contractors.Find(model.ContractorId);
            }

            contractor.Address             = model.Address;
            contractor.City                = model.City;
            contractor.Comments            = model.Comments;
            contractor.ContactFirstName    = model.ContactFirstName;
            contractor.ContactLastName     = model.ContactLastName;
            contractor.ContractCompanyName = model.ContractCompanyName;
            contractor.Email               = model.Email;
            contractor.OfficeTelephone     = model.OfficeTelephone;
            contractor.MCPNumber           = model.MCPNumber;
            contractor.MCPExpiration       = model.MCPExpiration;
            contractor.State               = model.State;
            contractor.Zip = model.Zip;
            contractor.ContractorTypeId = model.ContractorTypeId;


            if (isNew)
            {
                db.Contractors.Add(contractor);
            }

            db.SaveChanges();

            return(Json(contractor.ContractorID, JsonRequestBehavior.AllowGet));
        }
Beispiel #14
0
        public ActionResult SaveIncident(ShiftEntryViewModel _incident)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();

            ShiftEntryViewModel.Assist[] assists = js.Deserialize <ShiftEntryViewModel.Assist[]>(_incident.Assists.ToString());

            using (MTCDBEntities db = new MTCDBEntities())
            {
                try
                {
                    MTCIncident Incident = new MTCIncident();

                    Incident.IncidentID  = Guid.NewGuid();
                    Incident.Lat         = 0.00;
                    Incident.Lat         = 0.00;
                    Incident.UserPosted  = HttpContext.User.Identity.Name;
                    Incident.DatePosted  = DateTime.Now;
                    Incident.fromTruck   = 0;
                    Incident.TruckNumber = _incident.Truck;
                    Incident.Beat        = _incident.Beat;

                    //Add new incident
                    db.MTCIncidents.Add(Incident);

                    //save changes
                    db.SaveChanges();

                    //add preassist
                    foreach (ShiftEntryViewModel.Assist assist in assists)
                    {
                        //Add PreAssist
                        MTCPreAssist PA = new MTCPreAssist();
                        PA.PreAssistID          = Guid.NewGuid();
                        PA.IncidentID           = Incident.IncidentID;
                        PA.Direction            = assist.DIR;
                        PA.Position             = assist.POS;
                        PA.CHPIncidentType      = assist.IC;
                        PA.CHPLogNumber         = assist.CHPIncLogNum;
                        PA.Lat                  = 0.00;
                        PA.Lon                  = 0.00;
                        PA.datePosted           = DateTime.Now;
                        PA.Freeway              = assist.Highway;
                        PA.IncidentSurveyNumber = _incident.IncidentSurvNum;
                        PA.DriverID             = new Guid(_incident.Driver);

                        db.MTCPreAssists.Add(PA);

                        //Add Assists
                        MTCAssist AS = new MTCAssist();
                        AS.MTCAssistID        = Guid.NewGuid();
                        AS.IncidentID         = Incident.IncidentID;
                        AS.TrafficCollision   = assist.TC;
                        AS.DebrisOnly         = assist.DO;
                        AS.Breakdown          = assist.BD;
                        AS.Other              = assist.O;
                        AS.TransportType      = assist.TransCode;
                        AS.StartODO           = _incident.LogOnOd;
                        AS.EndODO             = _incident.LogOffOd;
                        AS.DropSiteBeat       = _incident.Beat;
                        AS.DropSite           = assist.Area;
                        AS.State              = assist.LicPlateState;
                        AS.LicensePlateNumber = assist.LicPlateNum;
                        AS.VehicleType        = assist.VehType;
                        AS.DetailNote         = assist.DetailNote;
                        AS.Lat        = 0.00;
                        AS.Lon        = 0.00;
                        AS.datePosted = DateTime.Now;
                        AS.CallSign   = _incident.CallSign;
                        AS.TimeOnInc  = assist.TimeOnInc;
                        AS.TimeOffInc = assist.TimeOffInc;

                        db.MTCAssists.Add(AS);

                        //Add ActionTaken
                        string[] AT = assist.AP.Split(',');
                        for (int i = 0; i <= AT.Length - 1; i++)
                        {
                            MTCActionTaken action = new MTCActionTaken();
                            action.MTCActionTakenID = Guid.NewGuid();
                            action.MTCAssistID      = AS.MTCAssistID;
                            action.ActionTaken      = AT[i].ToString();

                            //add action taken
                            db.MTCActionTakens.Add(action);
                        }

                        db.SaveChanges();
                    }
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }



                return(Json(true, JsonRequestBehavior.AllowGet));
            }
        }