public ActionResult Edit([Bind(Include = "DrivingSchoolId,Name,Working_since,Email,PhoneNumber,UserName,About,Licences_training_for,Province,Cities_of_operation,Vehicles_used")] DrivingSchool model, string PasswordHash)
        {
            // check if a driving school with same name already exists
            DrivingSchool checkmodel = db.DrivingSchools.SingleOrDefault(x => x.Name == model.Name && x.Working_since == model.Working_since);

            // check if the username entered already exists
            DrivingSchool check_user_account = db.DrivingSchools.SingleOrDefault(x => x.UserName == model.UserName);

            // if there is no duplication
            if (checkmodel == null || check_user_account == null)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(model).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                // Give error based on the duplication found
                if (checkmodel == null)
                {
                    ModelState.AddModelError("", "A Driving School with the same name and Year of establishment" + (check_user_account == null ? " and username" : "") + " already exists. If you already have an account, please try to login.");
                }
                else
                {
                    ModelState.AddModelError("", "An account with the same username already exists. Please, try again with a different username.");
                }
            }

            return(View(model));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            DrivingSchool drivingSchool = db.DrivingSchools.Find(id);

            db.DrivingSchools.Remove(drivingSchool);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
 public void PlayerEnterVehicleEvent(Client player, Vehicle vehicle, sbyte seat)
 {
     if (vehicle.Model == (uint)VehicleHash.Taxi && seat == (sbyte)VehicleSeat.Driver)
     {
         // Check if the player has a taxi driver license
         if (DrivingSchool.GetPlayerLicenseStatus(player, Constants.LICENSE_TAXI) == -1)
         {
             player.WarpOutOfVehicle();
             player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_taxi_license);
         }
     }
 }
Example #4
0
        public void PlayerEnterVehicleEvent(Client player, Vehicle vehicle, sbyte seat)
        {
            if (vehicle.Model == (uint)VehicleHash.Taxi && seat == (sbyte)VehicleSeat.Driver)
            {
                if (DrivingSchool.GetPlayerLicenseStatus(player, Constants.LICENSE_TAXI) == -1)
                {
                    // Stop the vehicle's speedometer
                    player.TriggerEvent("removeSpeedometer");

                    player.WarpOutOfVehicle();
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_taxi_license);
                }
            }
        }
        // GET: DrivingSchools/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DrivingSchool drivingSchool = db.DrivingSchools.Find(id);

            if (drivingSchool == null)
            {
                return(HttpNotFound());
            }
            return(View(drivingSchool));
        }
        public ActionResult AddInstructor([Bind(Include = "DrivingSchoolId")] DrivingSchool model, string[] InstructorIds)
        {
            if (InstructorIds != null)
            {
                foreach (string instructorId in InstructorIds)
                {
                    DrivingSchool_Instructors drivingschool_instructors = new DrivingSchool_Instructors();
                    drivingschool_instructors.InstructorId    = instructorId;
                    drivingschool_instructors.DrivingSchoolId = model.DrivingSchoolId;
                    db.DrivingSchool_Instructors.Add(drivingschool_instructors);
                }
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        // GET: DrivingSchools/AddInstructor/DrivingSchoolId
        public ActionResult AddInstructor(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            DrivingSchool drivingSchool = db.DrivingSchools.Include(x => x.DrivingSchool_Instructors.Select(m => m.Instructor)).SingleOrDefault(y => y.DrivingSchoolId == id);;

            // Extract ID's of instructors which are related to this driving school
            string[] instructorsIds = drivingSchool.DrivingSchool_Instructors.Select(x => x.InstructorId).ToArray();

            // Load instructor objects with id which is present in the list above
            ViewBag.Instructors = db.Instructors.Where(x => !instructorsIds.Contains(x.InstructorId));

            return(View(drivingSchool));
        }
        public ActionResult RemoveInstructor([Bind(Include = "DrivingSchoolId")] DrivingSchool model, string[] InstructorIds)
        {
            // check if there are any instructors selected to be deleted
            if (InstructorIds != null)
            {
                DrivingSchool tmpmodel = db.DrivingSchools.Find(model.DrivingSchoolId);

                var removeInstructors = tmpmodel.DrivingSchool_Instructors.Where(x => InstructorIds.Contains(x.InstructorId)).ToList();
                foreach (var InstructorsToRemove in removeInstructors)
                {
                    db.Entry(InstructorsToRemove).State = EntityState.Deleted;
                }

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DrivingSchool drivingSchool = db.DrivingSchools.Include(x => x.DrivingSchool_Instructors.Select(m => m.Instructor)).SingleOrDefault(y => y.DrivingSchoolId == id);;

            // Extract ID's of instructors which are related to this driving school
            string[] instructorsIds = drivingSchool.DrivingSchool_Instructors.Select(x => x.InstructorId).ToArray();

            // Load instructor objects with id which is present in the list above
            ViewBag.Instructors = db.Instructors.Where(x => instructorsIds.Contains(x.InstructorId));


            if (drivingSchool == null)
            {
                return(HttpNotFound());
            }
            return(View(drivingSchool));
        }
Example #10
0
        public void DocumentOptionSelectedEvent(Client player, int tramitation)
        {
            int money = NAPI.Data.GetEntitySharedData(player, EntityData.PLAYER_MONEY);

            switch (tramitation)
            {
            case Constants.TRAMITATE_IDENTIFICATION:
                if (NAPI.Data.GetEntityData(player, EntityData.PLAYER_DOCUMENTATION) > 0)
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + Messages.ERR_PLAYER_HAS_IDENTIFICATION);
                }
                else if (money < Constants.PRICE_IDENTIFICATION)
                {
                    String message = String.Format(Messages.ERR_PLAYER_NOT_IDENTIFICATION_MONEY, Constants.PRICE_IDENTIFICATION);
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + message);
                }
                else
                {
                    String message = String.Format(Messages.INF_PLAYER_HAS_INDENTIFICATION, Constants.PRICE_IDENTIFICATION);
                    NAPI.Data.SetEntitySharedData(player, EntityData.PLAYER_MONEY, money - Constants.PRICE_IDENTIFICATION);
                    NAPI.Data.SetEntityData(player, EntityData.PLAYER_DOCUMENTATION, Globals.GetTotalSeconds());
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + message);
                    Database.LogPayment(player.Name, Messages.GEN_FACTION_TOWNHALL, Messages.GEN_IDENTIFICATION, Constants.PRICE_IDENTIFICATION);
                }
                break;

            case Constants.TRAMITATE_MEDICAL_INSURANCE:
                if (NAPI.Data.GetEntityData(player, EntityData.PLAYER_MEDICAL_INSURANCE) > Globals.GetTotalSeconds())
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + Messages.ERR_PLAYER_HAS_MEDICAL_INSURANCE);
                }
                else if (money < Constants.PRICE_MEDICAL_INSURANCE)
                {
                    String message = String.Format(Messages.ERR_PLAYER_NOT_MEDICAL_INSURANCE_MONEY, Constants.PRICE_MEDICAL_INSURANCE);
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + message);
                }
                else
                {
                    String message = String.Format(Messages.INF_PLAYER_HAS_MEDICAL_INSURANCE, Constants.PRICE_MEDICAL_INSURANCE);
                    NAPI.Data.SetEntitySharedData(player, EntityData.PLAYER_MONEY, money - Constants.PRICE_MEDICAL_INSURANCE);
                    NAPI.Data.SetEntityData(player, EntityData.PLAYER_MEDICAL_INSURANCE, Globals.GetTotalSeconds() + 1209600);
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + message);
                    Database.LogPayment(player.Name, Messages.GEN_FACTION_TOWNHALL, Messages.GEN_MEDICAL_INSURANCE, Constants.PRICE_MEDICAL_INSURANCE);
                }
                break;

            case Constants.TRAMITATE_TAXI_LICENSE:
                if (DrivingSchool.GetPlayerLicenseStatus(player, Constants.LICENSE_TAXI) > 0)
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + Messages.ERR_PLAYER_HAS_TAXI_LICENSE);
                }
                else if (money < Constants.PRICE_TAXI_LICENSE)
                {
                    String message = String.Format(Messages.ERR_PLAYER_NOT_TAXI_LICENSE_MONEY, Constants.PRICE_TAXI_LICENSE);
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + message);
                }
                else
                {
                    String message = String.Format(Messages.INF_PLAYER_HAS_TAXI_LICENSE, Constants.PRICE_TAXI_LICENSE);
                    NAPI.Data.SetEntitySharedData(player, EntityData.PLAYER_MONEY, money - Constants.PRICE_TAXI_LICENSE);
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + message);
                    DrivingSchool.SetPlayerLicense(player, Constants.LICENSE_TAXI, 1);
                    Database.LogPayment(player.Name, Messages.GEN_FACTION_TOWNHALL, Messages.GEN_TAXI_LICENSE, Constants.PRICE_TAXI_LICENSE);
                }
                break;

            case Constants.TRAMITATE_FINE_LIST:
                List <FineModel> fineList = Database.LoadPlayerFines(player.Name);
                if (fineList.Count > 0)
                {
                    NAPI.ClientEvent.TriggerClientEvent(player, "showPlayerFineList", NAPI.Util.ToJson(fineList));
                }
                else
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + Messages.INF_PLAYER_NO_FINES);
                }
                break;
            }
        }
Example #11
0
        public void LicenseCommand(Client player, string args)
        {
            if (player.GetData(EntityData.PLAYER_FACTION) == Constants.FACTION_POLICE && player.GetData(EntityData.PLAYER_RANK) == 6)
            {
                string[] arguments = args.Trim().Split(' ');
                if (arguments.Length == 3 || arguments.Length == 4)
                {
                    Client target = null;

                    // Get the target player
                    if (int.TryParse(arguments[2], out int targetId) && arguments.Length == 3)
                    {
                        target = Globals.GetPlayerById(targetId);
                    }
                    else
                    {
                        target = NAPI.Player.GetPlayerFromName(arguments[2] + arguments[3]);
                    }

                    // Check whether the target player is connected
                    if (target == null || target.HasData(EntityData.PLAYER_PLAYING) == false)
                    {
                        player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_NOT_FOUND);
                    }
                    else if (player.Position.DistanceTo(target.Position) > 2.5f)
                    {
                        player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_TOO_FAR);
                    }
                    else
                    {
                        string playerMessage = string.Empty;
                        string targetMessage = string.Empty;

                        switch (arguments[0].ToLower())
                        {
                        case Messages.ARG_GIVE:
                            switch (arguments[1].ToLower())
                            {
                            case Messages.ARG_WEAPON:
                                // Add one month to the license
                                target.SetData(EntityData.PLAYER_WEAPON_LICENSE, Globals.GetTotalSeconds() + 2628000);

                                playerMessage = string.Format(Messages.INF_WEAPON_LICENSE_GIVEN, target.Name);
                                targetMessage = string.Format(Messages.INF_WEAPON_LICENSE_RECEIVED, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;

                            default:
                                player.SendChatMessage(Constants.COLOR_HELP + Messages.GEN_LICENSE_COMMAND);
                                break;
                            }
                            break;

                        case Messages.ARG_REMOVE:
                            switch (arguments[1].ToLower())
                            {
                            case Messages.ARG_WEAPON:
                                // Adjust the date to the current one
                                target.SetData(EntityData.PLAYER_WEAPON_LICENSE, Globals.GetTotalSeconds());

                                playerMessage = string.Format(Messages.INF_WEAPON_LICENSE_REMOVED, target.Name);
                                targetMessage = string.Format(Messages.INF_WEAPON_LICENSE_LOST, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;

                            case Messages.ARG_CAR:
                                // Remove car license
                                DrivingSchool.SetPlayerLicense(target, Constants.LICENSE_CAR, -1);

                                playerMessage = string.Format(Messages.INF_CAR_LICENSE_REMOVED, target.Name);
                                targetMessage = string.Format(Messages.INF_CAR_LICENSE_LOST, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;

                            case Messages.ARG_MOTORCYCLE:
                                // Remove motorcycle license
                                DrivingSchool.SetPlayerLicense(target, Constants.LICENSE_MOTORCYCLE, -1);

                                playerMessage = string.Format(Messages.INF_MOTO_LICENSE_REMOVED, target.Name);
                                targetMessage = string.Format(Messages.INF_MOTO_LICENSE_LOST, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;

                            default:
                                break;
                            }
                            break;

                        default:
                            player.SendChatMessage(Constants.COLOR_HELP + Messages.GEN_LICENSE_COMMAND);
                            break;
                        }
                    }
                }
                else
                {
                    player.SendChatMessage(Constants.COLOR_HELP + Messages.GEN_LICENSE_COMMAND);
                }
            }
            else
            {
                player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_NOT_POLICE_CHIEF);
            }
        }
Example #12
0
        public void DocumentOptionSelectedEvent(Client player, int tramitation)
        {
            int money = player.GetSharedData(EntityData.PLAYER_MONEY);

            switch (tramitation)
            {
            case Constants.TRAMITATE_IDENTIFICATION:
                if (player.GetData(EntityData.PLAYER_DOCUMENTATION) > 0)
                {
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_has_identification);
                }
                else if (money < Constants.PRICE_IDENTIFICATION)
                {
                    string message = string.Format(ErrRes.player_not_identification_money, Constants.PRICE_IDENTIFICATION);
                    player.SendChatMessage(Constants.COLOR_ERROR + message);
                }
                else
                {
                    string message = string.Format(InfoRes.player_has_indentification, Constants.PRICE_IDENTIFICATION);
                    player.SetSharedData(EntityData.PLAYER_MONEY, money - Constants.PRICE_IDENTIFICATION);
                    player.SetData(EntityData.PLAYER_DOCUMENTATION, Globals.GetTotalSeconds());
                    player.SendChatMessage(Constants.COLOR_INFO + message);


                    Task.Factory.StartNew(() =>
                    {
                        // Log the payment made
                        Database.LogPayment(player.Name, GenRes.faction_townhall, GenRes.identification, Constants.PRICE_IDENTIFICATION);
                    });
                }
                break;

            case Constants.TRAMITATE_MEDICAL_INSURANCE:
                if (player.GetData(EntityData.PLAYER_MEDICAL_INSURANCE) > Globals.GetTotalSeconds())
                {
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_has_medical_insurance);
                }
                else if (money < Constants.PRICE_MEDICAL_INSURANCE)
                {
                    string message = string.Format(ErrRes.player_not_medical_insurance_money, Constants.PRICE_MEDICAL_INSURANCE);
                    player.SendChatMessage(Constants.COLOR_ERROR + message);
                }
                else
                {
                    string message = string.Format(InfoRes.player_has_medical_insurance, Constants.PRICE_MEDICAL_INSURANCE);
                    player.SetSharedData(EntityData.PLAYER_MONEY, money - Constants.PRICE_MEDICAL_INSURANCE);
                    player.SetData(EntityData.PLAYER_MEDICAL_INSURANCE, Globals.GetTotalSeconds() + 1209600);
                    player.SendChatMessage(Constants.COLOR_INFO + message);


                    Task.Factory.StartNew(() =>
                    {
                        // Log the payment made
                        Database.LogPayment(player.Name, GenRes.faction_townhall, GenRes.medical_insurance, Constants.PRICE_MEDICAL_INSURANCE);
                    });
                }
                break;

            case Constants.TRAMITATE_TAXI_LICENSE:
                if (DrivingSchool.GetPlayerLicenseStatus(player, Constants.LICENSE_TAXI) > 0)
                {
                    player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_has_taxi_license);
                }
                else if (money < Constants.PRICE_TAXI_LICENSE)
                {
                    string message = string.Format(ErrRes.player_not_taxi_license_money, Constants.PRICE_TAXI_LICENSE);
                    player.SendChatMessage(Constants.COLOR_ERROR + message);
                }
                else
                {
                    string message = string.Format(InfoRes.player_has_taxi_license, Constants.PRICE_TAXI_LICENSE);
                    player.SetSharedData(EntityData.PLAYER_MONEY, money - Constants.PRICE_TAXI_LICENSE);
                    player.SendChatMessage(Constants.COLOR_INFO + message);
                    DrivingSchool.SetPlayerLicense(player, Constants.LICENSE_TAXI, 1);


                    Task.Factory.StartNew(() =>
                    {
                        // Log the payment made
                        Database.LogPayment(player.Name, GenRes.faction_townhall, GenRes.taxi_license, Constants.PRICE_TAXI_LICENSE);
                    });
                }
                break;

            case Constants.TRAMITATE_FINE_LIST:
                Task.Factory.StartNew(() =>
                {
                    List <FineModel> fineList = Database.LoadPlayerFines(player.Name);
                    if (fineList.Count > 0)
                    {
                        player.TriggerEvent("showPlayerFineList", NAPI.Util.ToJson(fineList));
                    }
                    else
                    {
                        player.SendChatMessage(Constants.COLOR_INFO + InfoRes.player_no_fines);
                    }
                });
                break;
            }
        }
Example #13
0
        public void LicenseCommand(Client player, string args)
        {
            if (Faction.IsPoliceMember(player) && player.GetData(EntityData.PLAYER_RANK) == 6)
            {
                var arguments = args.Trim().Split(' ');
                if (arguments.Length == 3 || arguments.Length == 4)
                {
                    Client target;

                    // Get the target player
                    if (int.TryParse(arguments[2], out var targetId) && arguments.Length == 3)
                    {
                        target = Globals.GetPlayerById(targetId);
                    }
                    else
                    {
                        target = NAPI.Player.GetPlayerFromName(arguments[2] + arguments[3]);
                    }

                    // Check whether the target player is connected
                    if (target == null || target.GetData(EntityData.PLAYER_PLAYING) == null)
                    {
                        player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_found);
                    }
                    else if (player.Position.DistanceTo(target.Position) > 2.5f)
                    {
                        player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_too_far);
                    }
                    else
                    {
                        string playerMessage;
                        string targetMessage;

                        switch (arguments[0].ToLower())
                        {
                        case Commands.ARG_GIVE:
                            switch (arguments[1].ToLower())
                            {
                            case Commands.ARG_WEAPON:
                                // Add one month to the license
                                target.SetData(EntityData.PLAYER_WEAPON_LICENSE,
                                               Scheduler.GetTotalSeconds() + 2628000);

                                playerMessage = string.Format(InfoRes.weapon_license_given, target.Name);
                                targetMessage = string.Format(InfoRes.weapon_license_received, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;

                            default:
                                player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_LICENSE_COMMAND);
                                break;
                            }

                            break;

                        case Commands.ARG_REMOVE:
                            switch (arguments[1].ToLower())
                            {
                            case Commands.ARG_WEAPON:
                                // Adjust the date to the current one
                                target.SetData(EntityData.PLAYER_WEAPON_LICENSE, Scheduler.GetTotalSeconds());

                                playerMessage = string.Format(InfoRes.weapon_license_removed, target.Name);
                                targetMessage = string.Format(InfoRes.weapon_license_lost, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;

                            case Commands.ARG_CAR:
                                // Remove car license
                                DrivingSchool.SetPlayerLicense(target, Constants.LICENSE_CAR, -1);

                                playerMessage = string.Format(InfoRes.car_license_removed, target.Name);
                                targetMessage = string.Format(InfoRes.car_license_lost, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;

                            case Commands.ARG_MOTORCYCLE:
                                // Remove motorcycle license
                                DrivingSchool.SetPlayerLicense(target, Constants.LICENSE_MOTORCYCLE, -1);

                                playerMessage = string.Format(InfoRes.moto_license_removed, target.Name);
                                targetMessage = string.Format(InfoRes.moto_license_lost, player.Name);
                                player.SendChatMessage(Constants.COLOR_INFO + playerMessage);
                                target.SendChatMessage(Constants.COLOR_INFO + targetMessage);
                                break;
                            }

                            break;

                        default:
                            player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_LICENSE_COMMAND);
                            break;
                        }
                    }
                }
                else
                {
                    player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_LICENSE_COMMAND);
                }
            }
            else
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_police_chief);
            }
        }
 public Task <ValidationResult <DrivingSchool> > CreateDrivingSchool(DrivingSchool drivingSchool)
 {
     throw new NotImplementedException();
 }