public async Task<IHttpActionResult> UpdateLocation(LocationApiModel model) { if (ModelState.IsValid && model != null) { this.CurrentUser.Longitude = model.Long; this.CurrentUser.Latitude = model.Lat; var result = await this.userManager.UpdateAsync(this.CurrentUser); var map = await this.db.Maps.FindAsync(model.MapId); if (!this.IsPointInPolygon(map.Coordinates.ToList(), model.Long, model.Lat)) { new GcmProvider().CreateNotification(new PushNotificationData { Action = 5, Message = "Out of boundaries!", Data = new { MapId = map.Id } }, this.CurrentUser.RegistrationId).SendAsync().Wait(); } if (result.Succeeded) return this.Ok(new ApiResponse(200, Mapper.Map<UserApiModel>(this.CurrentUser))); return this.InternalServerError(new ApiResponse(500, Mapper.Map<UserApiModel>(this.CurrentUser))); } return this.BadRequest(new ApiResponse(400, model)); }
public async Task<IHttpActionResult> Location(LocationApiModel model) { if (ModelState.IsValid && model != null) { collection = mongoDb.GetCollection<object>("location"); var userId = (await db.Devices.FirstAsync(x => x.UniqueId.Equals(model.DeviceId))).UserId; var mapped = Mapper.Map<LocationModel>(model); mapped.Created = DateTime.Now; mapped.UserId = userId; var bson = BsonSerializer.Deserialize<ExpandoObject>(BsonDocument.Parse(JsonConvert.SerializeObject(mapped))); await collection.InsertOneAsync(bson); NotificationHub.GetHubContext().Clients.All.location(mapped); return Ok(new ApiResponse(200, mapped)); } return this.BadRequest(new ApiResponse(400)); }