public async Task SaveVisit(Visit visit) { //Convert the generic repository entity to the persistence specific entity. var visitEntity = new UserVisits() { CityId = visit.CityId, Created = visit.Created, StateId = (byte)visit.StateId, //This is a type conversion, which would ideally be made the same type all the way through if it can be helped. UserId = visit.User, VisitId = new Guid(visit.VisitId) }; using (var db = new VisitsContext(this.Options)) { try { db.UserVisits.Add(visitEntity); await db.SaveChangesAsync(); } catch (Exception exc) { throw new RepositoryException("Problem saving a visit.", exc); } } }
public async Task DeleteVisit(int userId, string visitId) { var visitIdGuid = new Guid(visitId); try { using (var db = new VisitsContext(this.Options)) { var visitEntity = db.UserVisits.Where(v => v.VisitId == visitIdGuid && v.UserId == userId).FirstOrDefault(); if (visitEntity != null) { db.UserVisits.Remove(visitEntity); await db.SaveChangesAsync(); } } } catch (Exception exc) { throw new RepositoryException("Problem deleting a visit.", exc); } }