Beispiel #1
0
        public User GetUserNullable(string email)
        {
            Model.ServiceDbContext db = new Model.ServiceDbContext();
            User user = db.Users.FirstOrDefault(u => u.Email.Equals(email));

            return(user);
        }
Beispiel #2
0
        public Comment GetComment(Comment query)
        {
            Model.ServiceDbContext db = new Model.ServiceDbContext();

            Comment comment = db.Comments.FirstOrDefault(p => p.Id.Equals(query.Id));

            if (comment == null)
            {
                throw new PostNotFoundException();
            }

            return(comment);
        }
Beispiel #3
0
        public IList <User> GetAllUsers(int skip, int amount)
        {
            if (amount > 64)
            {
                amount = 64;              //limit traffic
            }
            Model.ServiceDbContext db = new Model.ServiceDbContext();

            IQueryable <User> query = db.Users;
            var pagedQuery          = query.OrderBy(u => u.Id).Skip(skip).Take(amount).ToList();

            return(pagedQuery);
        }
Beispiel #4
0
        public Ad GetAd(string id)
        {
            Model.ServiceDbContext db = new Model.ServiceDbContext();

            Ad post = db.Ads.Include("Author").Include("Location").Include("Price")
                      .Include("ReservedBy").FirstOrDefault(a => a.Id.Equals(id));

            if (post == null)
            {
                throw new PostNotFoundException();
            }

            return(post);
        }
Beispiel #5
0
        /// <summary>
        /// Can query users by Email
        /// </summary>
        /// <param name="query">A User containing at least Id or Email</param>
        /// <returns></returns>
        public User GetUser(string email)
        {
            Model.ServiceDbContext db = new Model.ServiceDbContext();


            User user = db.Users.FirstOrDefault(u => u.Email.Equals(email));

            if (user == null)
            {
                throw new UserNotFoundException();
            }

            return(user);
        }
Beispiel #6
0
        //Obsolete
        public IList <Comment> GetComments(int skip, int amount)
        {
            if (amount > 64)
            {
                amount = 64;
            }

            Model.ServiceDbContext db = new Model.ServiceDbContext();

            IQueryable <Comment> query = db.Comments;

            var pagedQuery = query.OrderBy(p => p.DatePosted).Skip(skip).Take(amount).ToList();

            return(pagedQuery);
        }
Beispiel #7
0
        /// <summary>
        /// Makes sure we have placeholder locations in the database, if we find out that it's empty.
        /// </summary>
        private void SeedLocations()
        {
            Model.ServiceDbContext db = new Model.ServiceDbContext();
            int count = db.Locations.Count <Location>();

            if (count == 0)
            {
                MigrationSeed.SeedLocations();

                foreach (var location in MigrationSeed.Locations)
                {
                    RegisterLocation(location.Name, location.Type, location.Parent?.Name);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Makes sure we have placeholder users in the database, if we find out that it's empty.
        /// </summary>
        private void SeedUsers()
        {
            Model.ServiceDbContext db = new Model.ServiceDbContext();
            int count = db.Users.Count();

            if (count == 0)
            {
                MigrationSeed.SeedUsers();

                foreach (var user in MigrationSeed.Users)
                {
                    RegisterUser(user.Name, user.Email, "http://test.com/image.png", "password");
                }
            }
        }
Beispiel #9
0
 private void AddUser(User user)
 {
     Model.ServiceDbContext db = new Model.ServiceDbContext();
     db.Users.Add(user);
     db.SaveChanges();
 }
Beispiel #10
0
        public int CountUsers()
        {
            Model.ServiceDbContext db = new Model.ServiceDbContext();

            return(db.Users.Count());
        }