Ejemplo n.º 1
0
 public ResultHelper Post([FromBody] UserLocation UserLocation)
 {
     if (UserLocation == null)
     {
         return(new ResultHelper(true, UserLocation.UserLocationId, ResultHelper.UnSuccessMessage));
     }
     userLocationService.Create(UserLocation);
     return(new ResultHelper(true, UserLocation.UserLocationId, ResultHelper.SuccessMessage));
 }
Ejemplo n.º 2
0
        public static UserLocation ParseReverseIp(string reverseIp)
        {
            if (string.IsNullOrWhiteSpace(reverseIp))
            {
                return(null);
            }

            UserLocation location = new UserLocation
            {
                Location = reverseIp
            };

            string[] keyValues = reverseIp.Split(CommaSplitParam, StringSplitOptions.RemoveEmptyEntries);
            foreach (string[] keyValue in keyValues.Select(parameter => parameter.Split(EqualsSplitParam, 2, StringSplitOptions.RemoveEmptyEntries)).Where(keyValue => keyValue.Length == 2 && !string.IsNullOrWhiteSpace(keyValue[0])))
            {
                switch (keyValue[0].Trim().ToLowerInvariant())
                {
                case "lat":
                    double lat;
                    double.TryParse(keyValue[1], out lat);
                    location.Latitude = lat;
                    break;

                case "long":
                    double lon;
                    double.TryParse(keyValue[1], out lon);
                    location.Longitude = lon;
                    break;

                case "country":
                    location.Country = keyValue[1];
                    break;

                case "state":
                    location.State = keyValue[1];
                    break;

                case "city":
                    location.City = keyValue[1];
                    break;

                case "dma":
                    location.Dma = keyValue[1];
                    break;

                case "zip":
                    location.ZipCode = keyValue[1];
                    break;

                case "iso":
                    location.Iso = keyValue[1];
                    break;
                }
            }

            return(location);
        }
Ejemplo n.º 3
0
        public string UploadUserLocation(UserLocation userLocation)
        {
            string locationAddress = this.GeocodingHelper.GetLocationAddress(userLocation);

            userLocation.LocationAddress = locationAddress;
            var res = Context.AddUserLocation(Serializer.Serialize(userLocation));

            return(res.FirstOrDefault().ToString());
        }
 public static UserLocationDTO ToUserLocationDTO(this UserLocation u)
 {
     return(new UserLocationDTO(u.Type.ToString("g"), u.UserId)
     {
         UserId = u.UserId,
         Type = u.Type.ToString("g"),
         GPSLat = u.Location.gpsLat,
         GPSLong = u.Location.gpsLong
     });
 }
        public ActionResult Index(FormCollection form)
        {
            string       str1    = form["ListItem1"].ToString();
            string       str2    = form["ListItem2"].ToString();
            UserLocation userLoc = Session["userLocation"] as UserLocation;

            LocationsList = Session["LocationList"] as List <Coordinates>;
            return(Json(LocationsList, JsonRequestBehavior.AllowGet));
            //  return View();
        }
Ejemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "Id,Name")] UserLocation userLocation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userLocation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userLocation));
 }
Ejemplo n.º 7
0
 public UserLocationViewModel(UserLocation loc)
 {
     Id          = loc.Id;
     Description = loc.Description;
     Create      = loc.Create;
     Read        = loc.Read;
     Update      = loc.Update;
     Delete      = loc.Delete;
     AddedUserId = loc.AddedUserId;
 }
        public async Task ExecuteAsync(AddUserLocation message)
        {
            var id   = Guid.NewGuid();
            var date = DateTime.Now;

            var userLocation = new UserLocation(id, message.UserId, date, message.Latitude, message.Longitude, message.Height);
            await repository.SaveAsync(userLocation);

            await eventStore.StoreCommandAsync(message).ConfigureAwait(false);
        }
 public void UpdateUserLocation(string userId, UserLocation location)
 {
     if (_cache.TryGetValue(userId, out var value))
     {
         if (value is UserLocation)
         {
             _cache.Set(userId, location);
         }
     }
 }
Ejemplo n.º 10
0
        public IActionResult Post([FromBody] UserLocation user)
        {
            if (user == null)
            {
                return(BadRequest("Location is null."));
            }

            _dataRepository.Add(user);
            return(Ok(user));
        }
 public IActionResult GetUserLocation(UserLocation location)
 {
     if (!ModelState.IsValid)
     {
         ViewData["OrderSum"] = _orderService.GetOrderByUserName(User.Identity.Name).OrderSum;
         return(View());
     }
     _userService.AddUserLocation(location);
     _orderService.FinalyOrder(User.Identity.Name);
     return(Redirect("/"));
 }
Ejemplo n.º 12
0
        public IHttpActionResult GetUserLocation(int id)
        {
            UserLocation userlocation = db.UserLocations.Find(id);

            if (userlocation == null)
            {
                return(NotFound());
            }

            return(Ok(userlocation));
        }
Ejemplo n.º 13
0
        public ResultHelper Put(int id, [FromBody] UserLocation UserLocation)
        {
            if (UserLocation == null)
            {
                return(new ResultHelper(true, UserLocation.UserLocationId, ResultHelper.UnSuccessMessage));
            }


            userLocationService.Set(UserLocation);
            return(new ResultHelper(true, UserLocation.UserLocationId, ResultHelper.SuccessMessage));
        }
Ejemplo n.º 14
0
        public ResultHelper Delete(int id)
        {
            UserLocation UserLocation = userLocationService.Get(id);

            if (UserLocation == null)
            {
                return(new ResultHelper(true, UserLocation.UserLocationId, ResultHelper.UnSuccessMessage));
            }
            userLocationService.Delete(UserLocation);
            return(new ResultHelper(true, UserLocation.UserLocationId, ResultHelper.SuccessMessage));
        }
Ejemplo n.º 15
0
        public ActionResult Create([Bind(Include = "Id,Name")] UserLocation userLocation)
        {
            if (ModelState.IsValid)
            {
                db.UserLocation.Add(userLocation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userLocation));
        }
Ejemplo n.º 16
0
 public void Add(UserLocation userLocation)
 {
     if (userLocation.Type == UserLocation.LocationType.Start)
     {
         StartLocations.Append(userLocation);
     }
     else
     {
         EndLocations.Append(userLocation);
     }
 }
        public bool TryGetUserLocation(string userId, out UserLocation location)
        {
            if (_cache.TryGetValue(userId, out var value) && value is UserLocation)
            {
                location = (UserLocation)value;
                return(true);
            }

            location = null;
            return(false);
        }
        public async Task AddUserLocationAsync(UserLocation location)
        {
            await _context.UserLocation.InsertOneAsync(location);

            if (_cachingEnabled)
            {
                await _cache.InsertAsync($"UserLocation:UserID:{location.UserId}", new CacheItem(JsonConvert.SerializeObject(location))
                {
                    Expiration = new Expiration(ExpirationType.Absolute, TimeSpan.FromMinutes(_expirationTime))
                });
            }
        }
Ejemplo n.º 19
0
        public IHttpActionResult PostUserLocation(UserLocation userlocation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.UserLocations.Add(userlocation);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = userlocation.UserLocationID }, userlocation));
        }
Ejemplo n.º 20
0
        private bool Cheakable()
        {
            if (Username.Text == "")
            {
                ErrorPage ER = new ErrorPage();
                ER.Show();
                ER.Error_Lable.Content = "نام ورزشکار را وارد کنید";
                Username.Focus();
                return(false);
            }
            if (UserFamily.Text == "")
            {
                ErrorPage ER = new ErrorPage();
                ER.Show();

                UserFamily.Focus();
                return(false);
            }
            if (UserTel.Text == "")
            {
                ErrorPage ER = new ErrorPage();
                ER.Show();

                UserTel.Focus();
                return(false);
            }
            if (UserFamily.Text == "")
            {
                ErrorPage ER = new ErrorPage();
                ER.Show();

                UserFamily.Focus();
                return(false);
            }
            if (UserAge.Text == "")
            {
                ErrorPage ER = new ErrorPage();
                ER.Show();

                UserAge.Focus();
                return(false);
            }
            if (UserLocation.Text == "")
            {
                ErrorPage ER = new ErrorPage();
                ER.Show();
                UserLocation.Focus();
                return(false);
            }


            return(true);
        }
Ejemplo n.º 21
0
 public void Create(int userId, int locationId)
 {
     if (!DB.UserLocations.Any(u => u.UserId == userId && u.LocationId == locationId))
     {
         UserLocation userLocation = new UserLocation()
         {
             UserId     = userId,
             LocationId = locationId
         };
         DB.UserLocations.Add(userLocation);
     }
 }
Ejemplo n.º 22
0
        public ActionResult RevokeLocation(int loc)
        {
            int          idUsr    = (int)Session["usr"];
            UserLocation location = context.FindUserLocation(idUsr, loc);

            if (location != null)
            {
                context.Remove(location);
                context.SaveChanges();
            }
            return(RedirectToAction("Assignment", "UserLocation", new { id = idUsr }));
        }
Ejemplo n.º 23
0
        public string GetLocationAddress(UserLocation userLocation)
        {
            string geoCodingAPIKey = ConfigurationManager.AppSettings["GeoCodingAPIKey"].ToString();
            //IGeocoder geocoder = new GoogleGeocoder("AIzaSyB3qF_1mFfeu2Jwt6Z9zmFK6GrbthVaLwI");//api key
            string   formattedAdrress;
            Location loc;
            IEnumerable <Address> addressList = null;
            Boolean errorFlag = false;

            IGeocoder geocoder;

            geocoder = new GoogleGeocoder(geoCodingAPIKey);//api key

            try
            {
                formattedAdrress = string.Empty;
                loc         = new Location(Double.Parse(userLocation.Latitude.ToString()), Double.Parse(userLocation.Longitude.ToString()));
                addressList = geocoder.ReverseGeocode(loc);
                if (addressList == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                errorFlag = true;
            }

            try
            {
                if (errorFlag)
                {
                    geocoder         = new GoogleGeocoder();//api key
                    formattedAdrress = string.Empty;
                    loc         = new Location(Double.Parse(userLocation.Latitude.ToString()), Double.Parse(userLocation.Longitude.ToString()));
                    addressList = geocoder.ReverseGeocode(loc);
                }
            }
            catch (Exception ex1)
            {
            }

            if (addressList != null && addressList.Count() > 0)
            {
                formattedAdrress = addressList.First().FormattedAddress;
            }
            else
            {
                formattedAdrress = ConfigurationManager.AppSettings["GeoCodingAddressNotFoundText"].ToString();
            }

            return(formattedAdrress);
        }
Ejemplo n.º 24
0
        public IHttpActionResult PostUserLastLocation(UserLocation location)
        {
            if (!Session.Authorized)
            {
                return(Unauthorized());
            }

            var inserted = _locationRepo.InsertUserLastLocation(Session.User.Id, location.Latitude, location.Longitude,
                                                                location.Date);

            return(Ok(inserted));
        }
Ejemplo n.º 25
0
 public UserLocationViewModel(UserLocation l)
 {
     this.Id             = l.Id;
     this.Description    = l.Description;
     this.RegisteredUser = l.RegisteredUser;
     this.LocationId     = l.LocationId;
     this.Create         = l.Create;
     this.Read           = l.Read;
     this.Update         = l.Update;
     this.Delete         = l.Delete;
     this.AddedUserId    = l.AddedUserId;
 }
Ejemplo n.º 26
0
 public bool Delete(Guid id)
 {
     try
     {
         HttpResponseMessage resp = client.DeleteAsync(UrlHelper.Userlocations_Url + @"/DeleteLocation/" + id).Result;
         UserLocation        t    = JsonConvert.DeserializeObject <UserLocation>(resp.Content.ReadAsStringAsync().Result);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 27
0
        public bool ChangeLoginStatus(ViewUser user, int status, UserLocation userLocaiton)
        {
            try
            {
                ConnectionObj.Open();
                CommandObj.CommandText = "UDSP_ChangeLoginStatus";
                CommandObj.CommandType = CommandType.StoredProcedure;
                CommandObj.Parameters.AddWithValue("@UserId", user.UserId);
                CommandObj.Parameters.AddWithValue("@IpAddress", userLocaiton.IPAddress ?? (object)DBNull.Value);

                CommandObj.Parameters.AddWithValue("@MacAddress", user.MacAddress ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@LoginDateTime", user.LogInDateTime);
                CommandObj.Parameters.AddWithValue("@LogOutDateTime", user.LogOutDateTime);
                CommandObj.Parameters.AddWithValue("@ActiveStatus", status);

                //----------------These line shuld be comment out during working in real server "192.168.2.62"-----------------
                CommandObj.Parameters.AddWithValue("@CountryName", userLocaiton.CountryName ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@CountryCode", userLocaiton.CountryCode ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@CityName", userLocaiton.CityName ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@RegionName", userLocaiton.RegionName ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@ZipCode", userLocaiton.ZipCode ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@Latitude", userLocaiton.Latitude ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@Longitude", userLocaiton.Longitude ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@TimeZone", userLocaiton.TimeZone ?? (object)DBNull.Value);
                CommandObj.Parameters.AddWithValue("@IsValidLogin", userLocaiton.IsValidLogin);

                //---------------------End -------------------------------------
                CommandObj.Parameters.Add("@RowAffected", SqlDbType.Int);
                CommandObj.Parameters["@RowAffected"].Direction = ParameterDirection.Output;
                CommandObj.ExecuteNonQuery();
                int rowAffected = Convert.ToInt32(CommandObj.Parameters["@RowAffected"].Value);
                if (rowAffected > 0)
                {
                    return(true);
                }

                return(false);
            }

            catch (Exception e)
            {
                Log.WriteErrorLog(e);
                throw new Exception("Could not change login status", e);
            }
            finally
            {
                ConnectionObj.Close();
                CommandObj.Dispose();
                CommandObj.Parameters.Clear();
            }
        }
Ejemplo n.º 28
0
        public IHttpActionResult DeleteUserLocation(int id)
        {
            UserLocation userlocation = db.UserLocations.Find(id);

            if (userlocation == null)
            {
                return(NotFound());
            }

            db.UserLocations.Remove(userlocation);
            db.SaveChanges();

            return(Ok(userlocation));
        }
Ejemplo n.º 29
0
        // GET: UserLocations/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserLocation userLocation = db.UserLocation.Find(id);

            if (userLocation == null)
            {
                return(HttpNotFound());
            }
            return(View(userLocation));
        }
Ejemplo n.º 30
0
        public void Value_ShouldBeEmpty_WhenIpIsEmpty()
        {
            // Arrange
            var userLocation = new UserLocation(string.Empty, 10.0f, 10.0f, "ISP", "ZZ");

            _userStorage.Location().Returns(userLocation);
            var location = new TruncatedLocation(_userStorage);

            // Act
            var result = location.Ip();

            // Assert
            result.Should().Be(string.Empty);
        }
Ejemplo n.º 31
0
        public static void Save(UserLocationDO model, int userID)
        {
            Repository<UserLocation> rep = new Repository<UserLocation>(CheckoutDataContextProvider.Instance);
            UserLocation dbObject;
            if (rep.GetAll().Where(x => x.UserName == model.UserName && x.LocationID == model.LocationID).SingleOrDefault() != null)
            {
                throw new BusinessException("Bu kullanıcı için bu lokasyon tanımlanmış");
            }

            if (model.ID == 0)
            {
                dbObject = new UserLocation();
                Mapper.Map<UserLocationDO, UserLocation>(model, dbObject);
                rep.InsertOnSubmit(dbObject);
            }
            else
            {
                dbObject = rep.GetAll().Where(x => x.ID == model.ID).SingleOrDefault();
                Mapper.Map<UserLocationDO, UserLocation>(model, dbObject);
            }

            rep.DCP.CommitChanges(userID);
            Mapper.Map<UserLocation, UserLocationDO>(dbObject, model);
        }
Ejemplo n.º 32
0
        public Form1()
        {
            InitializeComponent();
            
            EQInfo_label1.Text = "";
            EQInfo_label2.Text = "";
            EQInfo_label3.Text = "";
            EQInfo_label4.Text = "";
            Today_label.Text = "Today: " + DateTime.Now.ToString("dd.MMMM");
            my_dyn_loc_label1.Text = "";
            location_linkLabel1.Text = "";

            // A list for the quakes
            eq_list = new List<EQ_ListData>();
            userLocationJSON = new UserLocation();
            
            try
            {
                // Get user location data from the interweb
                userLocation = userLocationJSON._download_serialized_json_data<UserLocation>("http://ipinfo.io/json");
                // Get the quake data from the interweb
                eq_data = new EQ_Data();
            }
            catch (WebException e)
            {
                Console.WriteLine(e.Message);
                MessageBox.Show("No interweb. Me need interweb to work.", "Copmuter says no!", MessageBoxButtons.OK);
                // Disable the button if there's no internet connection.
                Get_button.Enabled = false;
                
            }

            // Display the user location.
            my_dyn_loc_label1.Text = "You are in "+ userLocation.city;

        }
Ejemplo n.º 33
0
 public UserLocation reportUserLocation(UserLocation UserLocation)
 {
     LocationSingleton.Instance.AddOrUpdateUserLocation(UserLocation);
     return UserLocation;
 }
Ejemplo n.º 34
0
 public void AddOrUpdateUserLocation(UserLocation userLocation)
 {
     UserLocation gotUserLocation=null;
     userLocationDictionary.TryGetValue(userLocation.UserName, out gotUserLocation);
     if (gotUserLocation != null)
     {
         gotUserLocation.Latitude = userLocation.Latitude;
         gotUserLocation.Longitude = userLocation.Longitude;
     }
     else
     {
         userLocations.Add(userLocation);
         userLocationDictionary.Add(userLocation.UserName, userLocation);
     }
 }