Ejemplo n.º 1
0
        public async Task <IActionResult> CancelPickup(PickupModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageOrders))
            {
                return(AccessDeniedView());
            }

            var shipment = model.ShipmentId.HasValue ? await _shipmentService.GetShipmentByIdAsync(model.ShipmentId.Value) : null;

            var batch = model.BatchId.HasValue ? await _easyPostService.GetBatchByIdAsync(model.BatchId.Value) : null;

            var(_, error) = await _easyPostService.CancelPickupAsync(shipment, batch);

            if (!string.IsNullOrEmpty(error))
            {
                var locale = await _localizationService.GetResourceAsync("Plugins.Shipping.EasyPost.Error");

                _notificationService.ErrorNotification(string.Format(locale, error, Url.Action("List", "Log")), false);
            }
            else
            {
                var locale = await _localizationService.GetResourceAsync("Plugins.Shipping.EasyPost.Success");

                _notificationService.SuccessNotification(locale);
            }

            if (batch is not null)
            {
                return(RedirectToAction("BatchEdit", "EasyPost", new { id = batch.Id }));
            }

            return(RedirectToAction("ShipmentDetails", "Order", new { id = shipment?.Id ?? 0 }));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Modify(PickupModel model)
        {
            if (ModelState.IsValid)
            {
                // To convert the user uploaded Photo as Byte Array before save to DB
                byte[] imageData = null;
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase poImgFile = Request.Files["Picture"];

                    using (var binary = new BinaryReader(poImgFile.InputStream))
                    {
                        imageData = binary.ReadBytes(poImgFile.ContentLength);
                    }
                    var curUser = User.Identity.GetUserId();
                    using (var db = new PickupModel())
                    {
                        var player = db.Players.FirstOrDefault(p => p.PlayerID == curUser);
                        player.Picture = imageData;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(PartialView(model));
        }
Ejemplo n.º 3
0
        public ActionResult ApplyPickup(string id)
        {
            PickupModel pickup = new PickupModel();

            pickup.Id = id;
            return(View(pickup));
        }
Ejemplo n.º 4
0
        public ActionResult PlayerDisplay(string playerId, int matchId)
        {
            using (var db = new PickupModel())
            {
                var match = db.Matches.FirstOrDefault(m => m.MatchID == matchId);

                int playerCount = 0;
                List <PlayerModel> curPlayers = new List <PlayerModel>();

                var player = db.Players.FirstOrDefault(p => p.PlayerID == playerId);
                if (player != null)
                {
                    curPlayers.Add(new PlayerModel
                    {
                        playerCurRole  = player.CurRole,
                        playerUsername = player.Username,
                        playerPicture  = player.Picture,
                        playerID       = player.PlayerID
                    });
                }
                MatchesModel matches = new MatchesModel
                {
                    matchID          = match.MatchID,
                    matchMap         = match.MatchMap,
                    matchHost        = match.MatchHost,
                    matchAdmin       = match.MatchAdmin,
                    matchPlayerCount = playerCount,
                    matchPlayers     = curPlayers
                };
                return(PartialView(matches));
            }
        }
Ejemplo n.º 5
0
        public ActionResult MatchInfo(int matchId)
        {
            using (var db = new PickupModel())
            {
                var match = db.Matches.FirstOrDefault(m => m.MatchID == matchId);

                int playerCount = 0;
                List <PlayerModel> curPlayers = new List <PlayerModel>();
                foreach (var player in db.Players.Where(n => n.CurMatch == match.MatchID))
                {
                    curPlayers.Add(new PlayerModel
                    {
                        playerID = player.PlayerID
                    });
                    playerCount++;
                }

                MatchesModel matches = new MatchesModel
                {
                    matchID          = match.MatchID,
                    matchMap         = match.MatchMap,
                    matchHost        = match.MatchHost,
                    matchAdmin       = match.MatchAdmin,
                    matchPlayerCount = playerCount,
                    matchPlayers     = curPlayers
                };
                return(PartialView(matches));
            }
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(string id)
        {
            PickupModel pickupModel = db.PickupModels.Find(id);

            db.PickupModels.Remove(pickupModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
 public FileContentResult PlayerPhotos(string playerId)
 {
     using (var db = new PickupModel())
     {
         var userImage = db.Players.FirstOrDefault(p => p.PlayerID == playerId).Picture;
         return(new FileContentResult(userImage, "image/jpeg"));
     }
 }
Ejemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "PickupId,Id,PickupDate")] PickupModel pickupModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pickupModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id = new SelectList(db.Users, "Id", "Name", pickupModel.Id);
     return(View(pickupModel));
 }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "PickupId,Id,PickupDate")] PickupModel pickupModel)
        {
            if (ModelState.IsValid)
            {
                db.PickupModels.Add(pickupModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Id = new SelectList(db.Users, "Id", "Name", pickupModel.Id);
            return(View(pickupModel));
        }
Ejemplo n.º 10
0
 public FileContentResult UserPhotos()
 {
     if (User.Identity.IsAuthenticated)
     {
         var curUser = User.Identity.GetUserId();
         using (var db = new PickupModel())
         {
             var userImage = db.Players.FirstOrDefault(p => p.PlayerID == curUser).Picture;
             return(new FileContentResult(userImage, "image/jpeg"));
         }
     }
     return(null);
 }
Ejemplo n.º 11
0
        private void Start()
        {
            if (Display == null)
            {
                Debug.LogWarning("No Display Assigned for Pick up View!");
            }

            m_pickupModel = GetComponent <PickupModel>();
            m_pickupModel.TriggerExited  += OnTriggerExited;
            m_pickupModel.TriggerEntered += OnTriggerEntered;
            m_pickupModel.PickedWeapon   += OnPickedUpWeapon;
            m_pickupModel.ChangeState    += OnStateChanged;
        }
Ejemplo n.º 12
0
        // GET: PickupModels/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PickupModel pickupModel = db.PickupModels.Find(id);

            if (pickupModel == null)
            {
                return(HttpNotFound());
            }
            return(View(pickupModel));
        }
Ejemplo n.º 13
0
        // GET: PickupModels/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PickupModel pickupModel = db.PickupModels.Find(id);

            if (pickupModel == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Id = new SelectList(db.Users, "Id", "Name", pickupModel.Id);
            return(View(pickupModel));
        }
Ejemplo n.º 14
0
        public void Join(int matchId)
        {
            // Call the addNewMessageToPage method to update clients.

            using (var db = new PickupModel())
            {
                //var curUserId = User.Identity.GetUserId();
                var    curUserId = Context.User.Identity.GetUserId();
                Player player    = db.Players.FirstOrDefault(p => p.PlayerID == curUserId);
                //Match match = db.Matches.FirstOrDefault(m => m.MatchID == matchId);
                player.CurMatch = matchId;
                db.SaveChanges();
                var newPlayerCount = db.Players.Where(p => p.CurMatch == matchId).Count();
                Clients.All.userJoined(matchId, player.PlayerID, newPlayerCount);
            }
        }
Ejemplo n.º 15
0
        public void CreateGame(string Map)
        {
            // Call the addNewMessageToPage method to update clients.

            using (var db = new PickupModel())
            {
                Match match = new Match {
                    MatchMap   = Map,
                    MatchAdmin = Context.User.Identity.GetUserId(),
                    MatchHost  = Context.User.Identity.GetUserId()
                };
                db.Matches.Add(match);
                db.SaveChanges();
                Clients.All.gameCreated(match.MatchID);
            }
        }
Ejemplo n.º 16
0
    void OnBatchRecieved(object bm)
    {
        Debug.Log("Start placing pickups");
        BatchModel batchModel = (BatchModel)bm;

        // Get the amount of resource points available for spawning obstacles in this batch
        int resource = batchModel.GetTotalPickupResources();

        // Get a random number for spawnChance
        float spawnChance = Random.Range(0, 100f);

        // Retrieve sub list of obstacles we can spawn given the spawnChance
        List <PickupModel> pickups = batchModel.GetPickupsWithSpawnChance(spawnChance);

        if (pickups.Count != 0)
        {
            for (int i = 0; i < pickups.Count; i++)
            {
                if (resource <= 0)
                {
                    break;
                }

                PickupModel pickup = pickups[Random.Range(0, pickups.Count)];

                // if there is room given the laneWeight and if the obstacle is available
                if (resource - pickup.laneWeight >= 0 && pickup.IsAvailable())
                {
                    // try to place obstacle in a random slot in the batch
                    bool succesfullyPlaced = batchModel.PlaceGameItemInSpawnPoint(pickup);
                    if (succesfullyPlaced)
                    {
                        resource -= pickup.laneWeight;
                        pickup.SetAvailable(false);
                    }
                }
            }
        }


        // dispatch ready
        EventManager.TriggerEvent(SpawnSystemEvents.PICKUPS_ASSIGNED, batchModel);
    }
Ejemplo n.º 17
0
        public async Task <IActionResult> CreatePickup(PickupModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageOrders))
            {
                return(AccessDeniedView());
            }

            var shipment = model.ShipmentId.HasValue ? await _shipmentService.GetShipmentByIdAsync(model.ShipmentId.Value) : null;

            var batch = model.BatchId.HasValue ? await _easyPostService.GetBatchByIdAsync(model.BatchId.Value) : null;

            //prepare the details to create a pickup
            var request = new CreatePickupRequest
            {
                Address      = model.PickupAddress?.ToEntity <Address>() ?? new(),
                Instructions = model.Instructions,
                MaxDate      = model.MaxDate,
                MinDate      = model.MinDate
            };

            var(_, error) = await _easyPostService.CreatePickupAsync(shipment, batch, request);

            if (!string.IsNullOrEmpty(error))
            {
                var locale = await _localizationService.GetResourceAsync("Plugins.Shipping.EasyPost.Error");

                _notificationService.ErrorNotification(string.Format(locale, error, Url.Action("List", "Log")), false);
            }
            else
            {
                var locale = await _localizationService.GetResourceAsync("Plugins.Shipping.EasyPost.Success");

                _notificationService.SuccessNotification(locale);
            }

            if (batch is not null)
            {
                return(RedirectToAction("BatchEdit", "EasyPost", new { id = batch.Id }));
            }

            return(RedirectToAction("ShipmentDetails", "Order", new { id = shipment?.Id ?? 0 }));
        }
Ejemplo n.º 18
0
        public ActionResult Index()
        {
            List <MatchesModel> matches = new List <MatchesModel>();

            using (var db = new PickupModel())
            {
                foreach (var match in db.Matches)
                {
                    int playerCount = 0;
                    List <PlayerModel> curPlayers = new List <PlayerModel>();
                    foreach (var player in db.Players.Where(n => n.CurMatch == match.MatchID))
                    {
                        curPlayers.Add(new PlayerModel
                        {
                            playerID       = player.PlayerID,
                            playerCurRole  = player.CurRole,
                            playerUsername = player.Username,
                            playerPicture  = player.Picture
                        });
                        playerCount++;
                    }
                    matches.Add(new MatchesModel
                    {
                        matchID          = match.MatchID,
                        matchMap         = match.MatchMap,
                        matchHost        = match.MatchHost,
                        matchAdmin       = match.MatchAdmin,
                        matchPlayerCount = playerCount,
                        matchPlayers     = curPlayers
                    });
                }
            }
            if (matches.Count == 0)
            {
                matches = null;
                return(View(matches));
            }
            matches.ToList();
            //matches.Add(new MatchesModel {  matchID = "0", matchMap = "Hacienda", matchPlayerCount = 3, matchHost = "Daddy_COol", matchAdmin = "Daddy_COol",  matchPlayers = curPlayers});
            //matches.Add(new MatchModel { })
            return(View(matches));
        }
Ejemplo n.º 19
0
 public async Task <ActionResult> ApplyPickup([Bind(Include = "PickupId,Id,PickupDate,AppUser")] PickupModel pickupModel, params string[] selectedRoles)
 {
     if (ModelState.IsValid)
     {
         var user = db.Users.Find(pickupModel.Id);
         if (user == null)
         {
             return(HttpNotFound());
         }
         var pickup = new PickupModel
         {
             AppUser    = user,
             PickupDate = pickupModel.PickupDate,
             Id         = pickupModel.Id
         };
         var result = db.PickupModels.Add(pickup);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 20
0
        public void EndGame(int matchId)
        {
            using (var db = new PickupModel())
            {
                Match match = new Match
                {
                    MatchID = matchId
                };
                List <Player> removePlayers = db.Players.Where(p => p.CurMatch == matchId).ToList();
                foreach (var remPlayer in removePlayers)
                {
                    remPlayer.CurMatch = null;
                }

                db.SaveChanges();
                db.Matches.Attach(match);
                db.Matches.Remove(match);
                db.SaveChanges();
                Clients.All.gameEnded(matchId);
            }
        }
Ejemplo n.º 21
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    var player = new Player {
                        PlayerID = user.Id, Username = model.UserName
                    };
                    using (var db = new PickupModel())
                    {
                        var players = db.Set <Player>();
                        players.Add(player);
                        db.SaveChanges();
                    }
                    //user.Players.PlayerID = user.Id;
                    //user.Players.Username = user.UserName;
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(PartialView(model));
        }
Ejemplo n.º 22
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();

            var db         = new PickupModel();
            var curUserObj = db.Players.FirstOrDefault(p => p.PlayerID == userId);
            var userInfo   = new IndexViewModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            var playerInfo = new Player
            {
                Username     = curUserObj.Username,
                Picture      = curUserObj.Picture,
                PreferedRole = curUserObj.PreferedRole
            };
            var model = new UserDetails
            {
                userDetails   = userInfo,
                playerDetails = playerInfo
            };

            return(PartialView(model));
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Morphs the pickup into a GTA custom pickup
 /// </summary>
 public bool Morph(PickupModel model)
 {
     return(Morph(PickupType.Custom, (int)model));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Prepare pickup model
        /// </summary>
        /// <param name="model">Pickup model</param>
        /// <param name="shipment">Shipment; pass null if it's a pickup for the batch</param>
        /// <param name="batch">Batch; pass null if it's a pickup for the shipment</param>
        /// <param name="addressId">Address id</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the pickup model
        /// </returns>
        public async Task <PickupModel> PreparePickupModelAsync(PickupModel model, Shipment shipment, EasyPostBatch batch, int?addressId)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var pickupId = shipment is not null
                ? await _genericAttributeService.GetAttributeAsync <string>(shipment, EasyPostDefaults.PickupIdAttribute)
                : batch?.PickupId;

            model.PickupId   = pickupId;
            model.ShipmentId = shipment?.Id;
            model.BatchId    = batch?.Id;

            if (!string.IsNullOrEmpty(pickupId))
            {
                var(pickup, _) = await _easyPostService.GetPickupAsync(pickupId);

                model.Created   = pickup is not null;
                model.Status    = pickup?.status ?? "not found";
                model.Purchased = string.Equals(pickup?.status, "scheduled", StringComparison.InvariantCultureIgnoreCase);
                if (model.Created && !model.Purchased)
                {
                    var(pickupRates, _) = await _easyPostService.GetPickupRatesAsync(pickup);

                    if (pickupRates?.Any() ?? false)
                    {
                        model.AvailablePickupRates = await pickupRates.OrderBy(rate => rate.Rate).SelectAwait(async rate =>
                        {
                            var rateName = $"{rate.Carrier} {rate.Service}".TrimEnd(' ');
                            var text     = $"{await _priceFormatter.FormatShippingPriceAsync(rate.Rate, true)} {rateName}";
                            return(new SelectListItem(text, rate.Id));
                        }).ToListAsync();
                    }
                    else
                    {
                        var locale = await _localizationService.GetResourceAsync("Plugins.Shipping.EasyPost.Pickup.Rate.None");

                        model.AvailablePickupRates.Add(new SelectListItem(locale, string.Empty));
                    }
                }
            }

            if (!model.Created)
            {
                var address = await _addressService.GetAddressByIdAsync(addressId ?? 0);

                if (address is not null)
                {
                    model.PickupAddress = address.ToModel(model.PickupAddress);
                }
                await _addressModelFactory.PrepareAddressModelAsync(model.PickupAddress, address);

                model.PickupAddress.CustomAddressAttributes.Clear();

                model.MinDate = DateTime.UtcNow.AddDays(1).Date;
                model.MaxDate = DateTime.UtcNow.AddDays(7).Date;
            }

            return(model);
        }
Ejemplo n.º 25
0
 public void Construct(PickupModel pickup)
 {
     _pickup = pickup;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Creates a custom model pickup
 /// </summary>
 public Pickup(Vector3 position, PickupModel model)
     : this(position, PickupType.Custom, (int)model, 50)
 {
 }
Ejemplo n.º 27
0
 private void Start()
 {
     m_pickupModel = GetComponent <PickupModel>();
 }
 private void Awake( )
 {
     _model = GetComponent <PickupModel> ( );
     _view  = GetComponent <PickupView> ( );
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Creates a custom model pickup
 /// </summary>
 public Pickup(Vector3 position, PickupModel model, int respawnTime = 30000)
     : this(position, PickupType.Custom, (int)model, respawnTime)
 {
 }
Ejemplo n.º 30
0
 public Pickup(Vector3 position, PickupModel model)
 {
     this.Position   = position;
     this.Model      = (ushort)model;
     this.PickupType = PickupType.Custom;
 }