Example #1
0
        public async Task <Visit> GetVisit(string visitId)
        {
            var        vid         = new Guid(visitId);
            UserVisits visitEntity = null;

            try
            {
                using (var db = new VisitsContext(this.Options))
                    visitEntity = db.UserVisits.Where(v => v.VisitId == vid).FirstOrDefault();
            }
            catch (Exception exc)
            {
                throw new RepositoryException("Problem getting a visit.", exc);
            }

            Visit result = null;

            //Convert the entity framework entity (or whatever persistence technology specific entity) to the
            //generic repository entity.
            if (visitEntity != null)
            {
                result = new Visit()
                {
                    CityId  = visitEntity.CityId,
                    Created = visitEntity.Created,
                    StateId = visitEntity.StateId,
                    User    = visitEntity.UserId,
                    VisitId = visitEntity.VisitId.ToString()
                }
            }
            ;

            return(result);
        }
Example #2
0
        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);
                }
            }
        }