Example #1
0
        public async Task <int> SavePositionAsync(string kidName)
        {
            Location pos = await helper.OnGetCurrentLocation();

            Position position = new Position(pos.Latitude, pos.Longitude);

            PinModel item = new PinModel
            {
                Lat   = position.Latitude,
                Log   = position.Longitude,
                Label = kidName ?? "S/N",
                Type  = (int)PinType.Place
            };

            try
            {
                if (item.Id == null)
                {
                    item.Id = Guid.NewGuid().ToString();

                    return(await Database.InsertAsync(item));
                }
                else
                {
                    return(await Database.UpdateAsync(item));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(-1);
            }
        }
Example #2
0
        public async Task <PinModel> TryGetPinDetailsAsync(RequestorModel requestor)
        {
            PinModel model = default;
            var      key   = _cacheKeyGenerator.GenerateKeyForPin(requestor.OpCoId, requestor.HouseholdId, requestor.ProfileId, requestor.PinType);

            var cache = _redisClient.Db0.Database.StringGet(key);

            if (cache.HasValue)
            {
                model = DeSerializePinModel(cache.ToString());
            }
            else
            {
                var loaded = await _dbContext.Pins.SingleOrDefaultAsync(x => x.OpcoId == requestor.OpCoId && x.HouseholdId == requestor.HouseholdId && x.ProfileId == requestor.ProfileId && x.PinType == requestor.PinType);

                if (loaded != null)
                {
                    model = new PinModel()
                    {
                        PinHash             = loaded.PinHash,
                        PinLocked           = loaded.PinLocked,
                        LockReason          = loaded.LockReason,
                        PinSalt             = loaded.PinSalt,
                        FailedAttemptsCount = 0,
                        LastFailedAttempt   = DateTime.MinValue
                    };
                    _redisClient.Db0.Database.StringSet(key, SerializePinModel(model));
                }
            }
            return(model);
        }
Example #3
0
        public ActionResult CheckPin(PinModel model) //TODO: need to refactor - too many returns
        {
            Session["CardNumber"] = null;
            var numberOfTriesObject = Session["NumberOfTries"];
            var numberOfTries       = numberOfTriesObject != null ? (int)numberOfTriesObject : 0;
            var isValidResult       = BusinessController.CheckPinNumber(model.CurrentCardNumber, model.Pin, numberOfTries);

            if (isValidResult.Successful)
            {
                Session["CardNumber"] = model.CurrentCardNumber;
                var redirect = RedirectToAction("GetOperations", "Home");
                return(redirect);
            }
            if (!isValidResult.Blocked)
            {
                numberOfTries++;
                Session["NumberOfTries"] = numberOfTries;
            }
            else
            {
                return(View("ErrorView", new ErrorModel {
                    ErrorText = "Your card were blocked", PreviousAction = "LoginCard"
                }));
            }

            return(View("ErrorView", new ErrorModel {
                ErrorText = "Your entered the wrong pin", PreviousAction = "LoginCard"
            }));
        }
Example #4
0
        public ActionResult CheckPin()
        {
            var model = new PinModel {
                FailCount = PinFailCount
            };

            return(View(model));
        }
Example #5
0
        private async Task LoadPinModelAsync(RequestorModel requestor)
        {
            _storedPinModel = await _pinDataStore.TryGetPinDetailsAsync(requestor);

            if (_storedPinModel is null)
            {
                throw new Exceptions.PinDoesntExistException();
            }
        }
 public static Pin ToPin(this PinModel user_pin)
 {
     return(new Pin
     {
         Label = user_pin.Label,
         Address = user_pin.Address,
         Position = new Position(user_pin.Latitude, user_pin.Longitude),
         IsVisible = user_pin.IsFavorite
     });
 }
Example #7
0
 public static PinViewViewModel ToViewViewModel(this PinModel model, ICommand command)
 {
     return(new PinViewViewModel(
                model.ID,
                model.Name,
                model.Description,
                model.Latitude,
                model.Longtitude,
                model.ImagePath,
                command));
 }
Example #8
0
        protected override MarkerOptions CreateMarker(Pin pin)
        {
            PinModel p = pin as PinModel;

            if (p != null)
            {
                return(CreateMarkerOptions(p));
            }

            return(base.CreateMarker(pin));
        }
        private PinModel CreatePin(Pin pin)
        {
            var newPin = new PinModel
            {
                Latitude  = pin.Position.Latitude,
                Longitude = pin.Position.Longitude,
                PinName   = pin.Label,
                UserId    = _authorization.GetUserId,
            };

            return(newPin);
        }
Example #10
0
        void OnDidSelectAnnotationView(object sender, MKAnnotationViewEventArgs e)
        {
            customMap.OnSelect = true;
            var pintoadd = new PinModel();

            var customView = e.View as CustomMKAnnotationView;

            foreach (X.Models.PinModel pin in customMap.Pins)
            {
                if (pin.Id.Equals(customView.Id))
                {
                    pintoadd = pin;
                }
            }
            //var newPin = new Xamarin.Forms.Maps.Position(pintoadd.Position.Latitude, pintoadd.Position.Longitude);
            var dMeters = 0.3 * customMap.VisibleRegion.Radius.Kilometers;
            var dLat    = dMeters / 111.11;

            Console.WriteLine("delta latitude: {0}", dLat);
            customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(pintoadd.Position.Latitude - dLat, pintoadd.Position.Longitude), customMap.VisibleRegion.Radius));
            customPinView = new UIView();
            customMap.Pins.Clear();
            if (pintoadd.Label == null)
            {
                pintoadd.Label = "Scuttle";
            }
            customMap.Pins.Add(pintoadd);
            customMap.CustomPin.Clear();
            customMap.CustomPin.Add(pintoadd);
            customMap.showInfoBox(customView.Id);
            //if (customView.emojis != null)
            //{
            //    customPinView.Frame = new CGRect(0, -100, 40, 40);
            //    var image = new UIImageView(new CGRect(0, 0, 20, 20));
            //    image.Image = UIImage.FromFile(customView.emojis[0]);
            //    var image2 = new UIImageView(new CGRect(30, 30, 25, 25));
            //    image2.Image = UIImage.FromFile(customView.emojis[1]);
            //    var image3 = new UIImageView(new CGRect(0, 60, 30, 30));
            //    image3.Image = UIImage.FromFile(customView.emojis[2]);
            //    var image4 = new UIImageView(new CGRect(15, 90, 35, 35));
            //    image4.Image = UIImage.FromFile(customView.emojis[3]);
            //    customPinView.AddSubview(image);
            //    customPinView.AddSubview(image2);
            //    customPinView.AddSubview(image3);
            //    customPinView.AddSubview(image4);
            //    customPinView.Center = new CGPoint(0, -(e.View.Frame.Height + 75));
            //    e.View.AddSubview(customPinView);
            //}
            //else
            //{
            //    Console.WriteLine("No emojis");
            //}
        }
Example #11
0
        public static Pin ToPin(this PinModel pinModel)
        {
            var pin = new Pin()
            {
                Label     = pinModel.Label,
                Position  = new Position(pinModel.Latitude, pinModel.Longitude),
                Address   = pinModel.Address,
                IsVisible = pinModel.IsFavorite
            };

            return(pin);
        }
Example #12
0
 public static PinViewModel ToViewModel(this PinModel model)
 {
     return(new PinViewModel(
                model.ID,
                model.UserID,
                model.Name,
                model.Description,
                model.Latitude,
                model.Longtitude,
                model.IsFavorite,
                model.ImagePath,
                model.CategoryID));
 }
Example #13
0
        public async Task RemovePinAsync(PinModel pin)
        {
            try
            {
                await _restService.DeleteAsync <PinModel>($"{Constants.GpsRest.BASE_URL}/pins", pin);

                IsCollectionUpdated = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #14
0
        public ActionResult CheckPin(PinModel model)
        {
            var isValid = BusinessController.CheckPinNumber(model.CardNumber, model.Pin);

            if (isValid)
            {
                var redirect = RedirectToAction("GetOperations", "Home");
                return(redirect);
            }
            return(View("CheckPinView", new PinModel {
                CardNumber = model.CardNumber, Pin = model.Pin
            }));
        }
Example #15
0
        public MainViewModel(PinModel model)
        {
            this.pinModel = model;

            items = new List <PinViewModel>();
            for (int i = 0; i <= 13; i++)
            {
                items.Add(new PinViewModel(model, i));
            }
            for (int i = 14; i < 14 + 6; i++)
            {
                items.Add(new PinViewModel(model, i, PinViewModel.MODE.ANALOG));
            }
        }
Example #16
0
        public static PinModel ToPinModel(this Pin pin, int categoryId = -1)
        {
            PinModel Model = new PinModel();

            Model.Name        = pin.Label;
            Model.Latitude    = pin.Position.Latitude;
            Model.Longtitude  = pin.Position.Longitude;
            Model.UserID      = App.CurrentUserId;
            Model.Description = (string)pin.Tag;
            Model.IsFavorite  = pin.Type == PinType.SavedPin;
            Model.ImagePath   = pin.Icon != null ? pin.Icon.AbsolutePath : string.Empty;
            Model.CategoryID  = categoryId;
            return(Model);
        }
Example #17
0
        public IActionResult Index(PinModel model)
        {
            string message;

            if (ModelState.IsValid)
            {
                message = "Pin :" + model.Pin;
            }
            else
            {
                message = "Failed to create the product. Please try again";
            }
            return(Content(message));
        }
Example #18
0
 public static PinViewModel ToPinViewModel(this PinModel pinModel)
 {
     return(new PinViewModel
     {
         Id = pinModel.Id,
         UserId = pinModel.UserId,
         PinName = pinModel.PinName,
         PinDescription = pinModel.Description,
         PinLatitude = pinModel.Latitude,
         PinLongitude = pinModel.Longitude,
         PinCategories = pinModel.Categories,
         FavoritPin = pinModel.FavoritPin
     });
 }
Example #19
0
        async Task AnimatePinStreaming(PinModel p, Marker marker, CancellationTokenSource cancelToken)
        {
            if (p.Id == null)
            {
                return;
            }

            Console.WriteLine("AnimatePinStreamRunning...");
            int currentEmojiIndex = 0;
            int animationCount    = 0;

            while (!cancelToken.IsCancellationRequested)
            {
                float duration = 1500; // milliseconds
                float fps      = 60;
                float step     = duration / fps;
                if (currentEmojiIndex > 3)
                {
                    currentEmojiIndex = 0;
                }

                var x    = 0f;
                var rand = new Random();

                x = rand.Next(10, 15);

                for (float i = 0; i < 1; i += 1.0f / step)
                {
                    //var markerImage = createBitmapFromLayoutWithText(p, i, currentEmojiIndex);
                    var markerImage = DrawPin(p, i, currentEmojiIndex, x);

                    if (markerImage == null)
                    {
                        System.Diagnostics.Debug.WriteLine("marker image is null");
                        break;
                    }

                    //p.Label = i.ToString();
                    marker.SetIcon(BitmapDescriptorFactory.FromBitmap(markerImage));
                    await Task.Delay((int)step);

                    markerImage.Dispose();
                    markerImage = null;
                }
                animationCount++;
                currentEmojiIndex++;
            }
            System.Diagnostics.Debug.WriteLine("AnimatePinStreaming canceled");
        }
Example #20
0
        MarkerOptions CreateMarkerOptions(PinModel pin)
        {
            //var inflater = Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) as Android.Views.LayoutInflater;
            //Android.Views.View view;

            //view = inflater.Inflate(Resource.Layout.XamarinMapInfoWindow, null);

            var marker = new MarkerOptions();

            marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            marker.SetTitle(pin.Label);
            marker.SetSnippet(pin.Id);
            marker.SetIcon(BitmapDescriptorFactory.FromBitmap(createBitmapFromLayoutWithText(pin, 0, 0)));
            return(marker);
        }
Example #21
0
 public ActionResult CheckPin(PinModel model)
 {
     if (ModelState.IsValid)
     {
         IsPinChecked = true;
         return(Redirect(LastActionUrl));
     }
     PinFailCount++;
     if (PinFailCount > 3)
     {
         return(RedirectToAction("Index"));
     }
     model.FailCount = PinFailCount;
     return(View(model));
 }
Example #22
0
        public static PinModel ToPinModel(this PinViewModel pinViewModel)
        {
            var pinModel = new PinModel()
            {
                Id          = pinViewModel.PinId,
                Label       = pinViewModel.Label,
                Latitude    = pinViewModel.Latitude,
                Longitude   = pinViewModel.Longitude,
                Address     = pinViewModel.Address,
                Description = pinViewModel.Description,
                IsFavorite  = pinViewModel.IsFavorite,
                UserId      = pinViewModel.UserId
            };

            return(pinModel);
        }
Example #23
0
        public static Pin ToPin(this PinModel model)
        {
            Pin pin = new Pin();

            pin.Label    = model.Name;
            pin.Tag      = model.Description;
            pin.Position = new Position(model.Latitude, model.Longtitude);
            pin.Type     = model.IsFavorite ? PinType.SavedPin : PinType.Place;
            if (!string.IsNullOrEmpty(model.ImagePath))
            {
                if (File.Exists(model.ImagePath))
                {
                    pin.Icon = BitmapDescriptorFactory.FromStream(File.OpenRead(model.ImagePath));
                }
            }
            return(pin);
        }
Example #24
0
        public ActionResult ValidatePin(PinModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Pin", model));
            }

            var response = loginService.Login(Session["CardNumber"].ToString(), model.Pin);

            if (!response.Success)
            {
                ModelState.AddModelError("INVALID_PIN", response.ErrorMessage);
                return(View("Pin", model));
            }

            return(RedirectToAction("Index", "Operation"));
        }
Example #25
0
        public async Task <IActionResult> PutPinAsync([FromBody] PinModel pin)
        {
            try
            {
                if (!ModelState.IsValid || pin == null)
                {
                    return(BadRequest());
                }

                await _repositoryService.UpdateAsync(pin);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
Example #26
0
        public IActionResult ChangePin(string id, [FromBody] PinModel pin) //function to change password
        {
            Employee user = new Employee();

            user.EmployeeId = Guid.Parse(id);
            user            = _dataAccessProvider.GetSingleEmployeeRecord(user);
            if (pin.CurrentPin == user.PinNum)
            {
                if (pin.NewPin == pin.ConfirmPin)
                {
                    user.PinNum = pin.NewPin;
                    _dataAccessProvider.UpdateEmployeeRecord(user);
                    return(Ok());
                }
                return(BadRequest("New pin does not match Confirm Pin"));
            }
            return(BadRequest("Current Pin is Wrong"));
        }
Example #27
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            pinModel         = new PinModel();
            vm               = new MainViewModel(pinModel);
            this.DataContext = vm;

            vm.SerialItems = System.IO.Ports.SerialPort.GetPortNames().ToList();

            if (App.CommandLineArgs != null)
            {
                var port  = App.CommandLineArgs[0];
                var index = vm.SerialItems.FindIndex(x => x == port);
                if (index >= 0)
                {
                    vm.SerialSelectedIndex = index;
                    ConnectClicked(null, null);
                }
            }
        }
Example #28
0
        public async Task DeletePinAsync(PinModel pin)
        {
            try
            {
                if (pin != null)
                {
                    PinModel Model = await _repositoryService.GetAsync <PinModel>(pin.ID);

                    if (Model != null)
                    {
                        await _repositoryService.DeleteAsync(Model);
                    }
                }
            }
            catch (SQLite.SQLiteException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #29
0
        public async Task <IActionResult> PopulateCacheAsync([FromQuery] int maxrecords)
        {
            var items = await _context.Pins.AsNoTracking().Take(maxrecords).ToListAsync();

            foreach (var item in items)
            {
                var model = new PinModel()
                {
                    PinHash             = item.PinHash,
                    PinSalt             = item.PinSalt,
                    PinLocked           = item.PinLocked,
                    FailedAttemptsCount = 0,
                    LastFailedAttempt   = DateTime.MinValue
                };
                var key = _keyGen.GenerateKeyForPin("vfde", item.HouseholdId, item.ProfileId, item.PinType);
                await _cacheClient.Db0.AddAsync(key, item);
            }
            return(this.Ok());
        }
Example #30
0
        public async Task ProcessRequestAsync(RequestorModel requestor, string newPin)
        {
            await _opcoVerifier.CheckIfOpCoHasPinServiceAsync(requestor.OpCoId);

            var model = new PinChangeVerificationModel()
            {
                OpCoId  = requestor.OpCoId,
                PinType = requestor.PinType,
                NewPin  = newPin
            };
            await _pinChangeVerifier.CheckNewPinAgainstRulesAsync(model);

            var newpin   = _pinHashGenerator.GeneratePinHashWithNewSalt(newPin);
            var pinmodel = new PinModel()
            {
                PinLocked = false,
                PinHash   = newpin.Hash,
                PinSalt   = newpin.Salt
            };

            await _pinRepository.CreateOrUpdatePinAsync(requestor, pinmodel);
        }