Exemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] DriverLocationModel driverLocationModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (string.IsNullOrEmpty(driverLocationModel.User.Id))
            {
                return(BadRequest());
            }

            var user = _context.Users.Find(driverLocationModel.User.Id);

            _context.Entry(driverLocationModel.User).CurrentValues.SetValues(user);

            // to do make enum Status
            driverLocationModel.Status  = "Open";
            driverLocationModel.InsDate = DateTime.Now;
            driverLocationModel.UpdDate = DateTime.Now;

            _context.Add(driverLocationModel);
            if (!string.IsNullOrEmpty(driverLocationModel.Id))
            {
                HttpContext.Session.SetString("DriverLocationModelId", driverLocationModel.Id);
            }

            await _context.SaveChangesAsync();

            return(PartialView("Display", driverLocationModel));
        }
Exemplo n.º 2
0
        // todo use it in further
        public bool ActiveByLastUpdate(DriverLocationModel dr)
        {
            var isActive    = true;
            var lastUpdTime = dr.UpdDate;
            var nowDateTime = DateTime.Now;

            var timeDiff = (nowDateTime - lastUpdTime).Seconds;

            if (timeDiff > 300)
            {
                isActive = false;
            }

            return(isActive);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit([FromRoute] string id, [FromBody] DriverLocationModel driverLocationModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != driverLocationModel.Id)
            {
                return(NotFound());
            }

            // get object from db
            var driverLocation = _context.DriverLocations.Find(id);

            //check status
            if (driverLocation.Status != driverLocationModel.Status)
            {
                driverLocation.Status  = driverLocationModel.Status;
                driverLocation.UpdDate = DateTime.Now;
            }

            if (driverLocation.Status != "Closed")
            {
                driverLocation.Latitude  = driverLocationModel.Latitude;
                driverLocation.Longitude = driverLocationModel.Longitude;
            }

            try
            {
                _context.Update(driverLocation);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DriverLocationModelExists(driverLocationModel.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(PartialView("Display", driverLocation));
        }
Exemplo n.º 4
0
        public bool DistanceIsOk(DriverLocationModel dr, ClientRequestModel cr)
        {
            var distance = 100D;
            var isLat1   = double.TryParse(dr.Latitude, out var lat1);
            var isLng1   = double.TryParse(dr.Longitude, out var lng1);
            var isLat2   = double.TryParse(cr.Latitude, out var lat2);
            var isLng2   = double.TryParse(cr.Longitude, out var lng2);

            if (isLat1 && isLng1 && isLat2 && isLng2)
            {
                distance = FuncHelper.Distance(lat1, lng1, lat2, lng2, 2);
            }

            if (distance > 5D)
            {
                return(false);
            }

            return(true);
        }