private static Options UpdateOptions(string value, Trails trail) { var option = trail.Option; dynamic update = JObject.Parse(value); var distance = update.Distance.Value ?? ""; if (!string.IsNullOrEmpty(distance.ToString())) { option.Distance = Convert.ToDouble(update.Distance.Value); } var peak = update.Peak.Value ?? ""; if (!string.IsNullOrEmpty(peak.ToString())) { option.Peak = Convert.ToInt32(update.Peak.Value); } var elevation = update.Elevation.Value ?? ""; if (!string.IsNullOrEmpty(elevation.ToString())) { option.Elevation = Convert.ToDouble(update.Elevation.Value); } if (!string.IsNullOrEmpty(update.SeasonStart.Value.ToString())) { option.SeasonStart_Id = DbMongoHelpers.TryParseObjectId(update.SeasonStart.Id.Value); } if (!string.IsNullOrEmpty(update.SeasonEnd.Value.ToString())) { option.SeasonEnd_Id = DbMongoHelpers.TryParseObjectId(update.SeasonEnd.Id.Value); } if (!string.IsNullOrEmpty(update.Type.Value.ToString())) { option.TrailType_Id = DbMongoHelpers.TryParseObjectId(update.Type.Id.Value); } if (!string.IsNullOrEmpty(update.DurationType.Value.ToString())) { option.TrailDurationType_Id = DbMongoHelpers.TryParseObjectId(update.DurationType.Id.Value); } option.GoodForKids = update.GoodForKids.Value; option.DogAllowed = update.DogAllowed.Value; return(option); }
public Task <Trails> GetTrailByIdAsync(string id) { var objId = DbMongoHelpers.TryParseObjectId(id); try { return(Db.GetCollection <Trails>("Trails") .FindAsync(i => i._id == objId).Result.SingleOrDefaultAsync()); } catch (Exception) { throw new ServerConnectionException("Connection to database faulted."); } }
private static async Task <ObjectId> InsertComment(string value, ObjectId newId) { dynamic comment = JObject.Parse(value); var id = DbMongoHelpers.TryParseObjectId((string)comment.Id.Value); await Db.GetCollection <Comments>("Comments").InsertOneAsync(new Comments { _id = newId, Comment = comment.Comment.Value, Rate = comment.Rate.Value, User_Id = DbMongoHelpers.TryParseObjectId(comment.User.Value) }); return(id); }