Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using DbInterface;
- using Model;
- using LiteDB;
- namespace DbImplementation
- {
- public class MapRepository : IMapRepository
- {
- private string _dbConnection = Connection.DB_CONNECTION;
- public void Create(Map map)
- {
- using (var db = new LiteDatabase(_dbConnection))
- {
- var maps = db.GetCollection<Map>("maps");
- maps.Insert(map);
- }
- }
- public void Delete(int id)
- {
- using (var db = new LiteDatabase(_dbConnection))
- {
- var maps = db.GetCollection<Map>("maps");
- maps.Delete(Map => Map.Id == id);
- }
- }
- public Map Get(int id)
- {
- using (var db = new LiteDatabase(_dbConnection))
- {
- var maps = db.GetCollection<Map>("maps");
- return maps.FindById(id);
- }
- }
- public IEnumerable<Map> GetAll()
- {
- using (var db = new LiteDatabase(_dbConnection))
- {
- return (IEnumerable<Map>)db.GetCollection<Map>("maps").FindAll();
- }
- }
- public void Update(int id, Map map)
- {
- using (var db = new LiteDatabase(_dbConnection))
- {
- var maps = db.GetCollection<Map>("maps");
- var theMap = maps.FindById(id);
- theMap.positions = map.positions;
- theMap.SecretKey = map.SecretKey;
- maps.Update(map);
- }
- }
- }
- public class Connection
- {
- public static string DB_CONNECTION = @"C:/tmp/test.db";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement