Created
February 3, 2020 14:39
-
-
Save LarsBergqvist/7afbaac56c26222bbedcf8b0dd2877a7 to your computer and use it in GitHub Desktop.
Repository implementation using Sqlite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LocPoc.Contracts; | |
using System; | |
using System.Collections.Generic; | |
namespace LocPoc.Repository.Sqlite | |
{ | |
public class LocationsRepository : ILocationsRepository | |
{ | |
private readonly SqliteContext _context; | |
public LocationsRepository(SqliteContext context) | |
{ | |
_context = context; | |
} | |
public Location Add(Location location) | |
{ | |
location.Id = Guid.NewGuid().ToString(); | |
_context.Locations.Add(location); | |
_context.SaveChanges(); | |
return location; | |
} | |
public void Delete(string id) | |
{ | |
var loc = _context.Locations.Find(id); | |
if (loc != null) | |
{ | |
_context.Locations.Remove(loc); | |
} | |
_context.SaveChanges(); | |
} | |
public Location Get(string id) | |
{ | |
var loc = _context.Locations.Find(id); | |
return loc; | |
} | |
public IEnumerable<Location> GetAll() | |
{ | |
return _context.Locations; | |
} | |
public Location Update(Location location) | |
{ | |
var loc = _context.Locations.Find(location.Id); | |
if (loc != null) | |
{ | |
loc.Name = location.Name; | |
loc.Description = location.Description; | |
loc.Latitude = location.Latitude; | |
loc.Longitude = location.Longitude; | |
} | |
_context.SaveChanges(); | |
return loc; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment