Inheritance: System.Data.Entity.DbContext
コード例 #1
0
ファイル: UserModel.cs プロジェクト: jasekiw/ShameTheThrones
        //public void LogIn(UserModel user)
        //{
        //    using (shamethethronesEntities db = new shamethethronesEntities())
        //    {
                
        //    }
        //}

        public bool isValid(string email, string password)
        {
            bool isValid = false;

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                //if we don't do this then we get an error turning it into bytes
                return false;
            }

            using (var db = new shamethethronesContext())
            {
                string encrypted = CalculateMD5Hash(password);
                var user = db.Users.FirstOrDefault(x => x.email == email);

                if (user != null)
                {
                    if (user.pasword == encrypted)
                    {
                        this.id = user.id;
                        this.UserName = user.username;
                       
                        isValid = true;
                    }
                }
            }
                return isValid;
        }
コード例 #2
0
 public static RatingListModel getLatestRatings()
 {
     var ratingList = new RatingListModel();
     using (var db = new shamethethronesContext())
     {
         var ratings = db.Ratings.Take(50).OrderByDescending(e => e.id).ToList();
         foreach(var rating in ratings)
         {
             var ratingModel = new RatingModel(rating);
             ratingList.add(ratingModel);
         }
     }
     return ratingList;
 }
コード例 #3
0
        public int UserId; // later on will be required

        public void add()
        {
            using (var db = new shamethethronesContext())
            {
                var rating = new Rating();
                rating.userId = this.UserId;
                rating.comment = this.Comment;
                rating.restroomId = this.RestroomId;
                rating.title = this.Title;
                rating.ratingValue = (byte) this.Rating;
                db.Ratings.Add(rating);
                db.SaveChanges();
            }
        }
コード例 #4
0
ファイル: UserModel.cs プロジェクト: jasekiw/ShameTheThrones
        public void Register(UserModel user)
        {
            using (var db = new shamethethronesContext())
            {
                User newUser = new User();

                newUser.username = user.UserName;
                newUser.email = user.Email;
                newUser.pasword = CalculateMD5Hash(user.Password);
                
                db.Users.Add(newUser);
                db.SaveChanges();
            }
        }
コード例 #5
0
 public RestroomModel(int id)
 {
     using (shamethethronesContext db = new shamethethronesContext())
     {
         Restroom restroom = db.Restrooms.Where(x => x.id == id).First(x => x.deletedAt == null);
        
         this.id = restroom.id;
         this.Address = restroom.address;
         this.City = restroom.city;
         this.Description = restroom.description;
         this.Gender = restroom.gender;
         this.State = restroom.state;
         this.ZipCode = restroom.zipCode.HasValue ? "" + restroom.zipCode.Value : "";
         this.userId = restroom.userId;
     }
 }
コード例 #6
0
        public List<RestroomSearchResultModel> GetRestrooms()
        {
            List<RestroomSearchResultModel> restroomResults = new List<RestroomSearchResultModel>();
            using (var db = new shamethethronesContext())
            {
                List<Restroom> restrooms = new List<Restroom>();

                var query =
                    db.Restrooms
                        .Where(x => this.SWLat <= x.coordX)
                        .Where(x => this.SWLong <= x.coordY)
                        .Where(x => this.NELat >= x.coordX)
                        .Where(x => this.NELong >= x.coordY)
                        .Take(100);
                restrooms = query.ToList();
                restroomResults = RestroomSearchResultModel.getListFromDatabaseModelsList(restrooms);
            }
            return restroomResults;
        } 
コード例 #7
0
 public void AddRestroom(RestroomModel bathroom)
 {
     using (var db = new shamethethronesContext())
     {
         Restroom newBathroom = new Restroom();
         newBathroom.userId = bathroom.userId;
         newBathroom.address = bathroom.Address;
         newBathroom.city = bathroom.City; // commented out until db is changed 
         newBathroom.state = bathroom.State; 
         newBathroom.zipCode = Int32.Parse(bathroom.ZipCode); 
         newBathroom.gender = bathroom.Gender;
         newBathroom.description = bathroom.Description;
         newBathroom.coordX = bathroom.coordX;
         newBathroom.coordY = bathroom.coordY;
         db.Restrooms.Add(newBathroom);
         db.SaveChanges(); //until testing is done
         bathroom.id = newBathroom.id; // sets the id so we can get it later
     }
 }
コード例 #8
0
 public double getAverageRating()
 {
     double average = -1;
     using (var db = new shamethethronesContext())
     {
         var ratingAverageResult =
             db.Database.SqlQuery<RatingAverageModel>(
                 "SELECT SUM(dbo.Rating.ratingValue) as sumOfRatings, COUNT(*) as total FROM dbo.Rating WHERE dbo.Rating.restroomId = " +
                 this.id).First();
         average = Math.Truncate((100 * ratingAverageResult.getAverage()) / 100);
     }
     return average;
 }
コード例 #9
0
        public RestroomWithRatingModel getRestroomWithRating(int restroomId)
        {
            using (var db = new shamethethronesContext())
            {
                Restroom restroomModel = db.Restrooms.Single(x => x.id == restroomId);
                var ratings = db.Ratings.Where(x => x.restroomId == restroomId).OrderByDescending(x => x.id).Take(50).ToList();


                var restroom = new RestroomModel(restroomModel);

                var ratingsListModel = new RatingListModel(ratings);
                
                var restroomWithRating = new RestroomWithRatingModel();
                restroomWithRating.restroomModel = restroom;
                restroomWithRating.ratingModels = ratingsListModel;

                return restroomWithRating;
            } 
        }
コード例 #10
0
 public static RatingAverageModel getRatingObject(int id)
 {
     double average = -1;
     using (var db = new shamethethronesContext())
     {
         var ratingAverageResult =
             db.Database.SqlQuery<RatingAverageModel>(
                 "SELECT SUM(dbo.Rating.ratingValue) as sumOfRatings, COUNT(*) as total FROM dbo.Rating WHERE dbo.Rating.restroomId = " +
                 id).First();
         return ratingAverageResult;
     }
 }