public async Task <IHttpActionResult> Post(Models.Quest quest) { if (!ModelState.IsValid) { return(BadRequest( )); } if (quest.Id == Guid.Empty) { quest.Id = Guid.NewGuid( ); } var esClient = new ESClient.Client(); var result = await esClient.Add(quest); return(Ok(result)); }
public async Task <IHttpActionResult> Migrate( ) { var esClient = new ESClient.Client(); bool success = true; using (var context = new Context( )) { var toIndex = context.Quests.Include(q => q.Treasures).Select(q => new Models.Quest { BeginDate = q.BeginDate, CoordEnd = new Models.Geo { Lat = q.EndLat, Lon = q.EndLong }, CoordStart = new Models.Geo { Lat = q.StartLat, Lon = q.StartLong }, Description = q.Description, Difficulty = q.Difficulty, EndDate = q.EndDate, Id = q.Id, Name = q.Name, Treasures = q.Treasures.Select(t => new Models.Treasure { Id = t.Id, Description = t.Description, Name = t.Name, Value = t.Value }).ToList( ) }); foreach (var i in toIndex) { success &= await esClient.Add(i); } } return(Ok(success)); }