Exemplo n.º 1
0
        public static Review CreateReview(int userID, int childCareID, int rate)
        {
            /*   var id = user.Reviews.Where(p => p.ChildCareID == childCareID).FirstOrDefault();
            if (id != null)
                throw new Exception("User already rated the ChildCare");*/

            using (var db = new FactoryModel())
            {
                User user = db.Users.Where(x => (x.UserID == userID)).Single();

                var id = user.Reviews.Where(p => p.ChildCareID == childCareID).FirstOrDefault();
                if (id != null)
                    throw new Exception("User already rated the ChildCare");

                var r = new Review();

                r.ChildCareID = childCareID;
                r.UserID = userID;
                r.Rate = rate;

                user.Reviews.Add(r);
                db.Reviews.Add(r);
                db.SaveChanges();
                RatingUpdate(db, userID, childCareID, rate);
                return r;
            }
        }
Exemplo n.º 2
0
        public static User CreateUser(string name, string address, string email)
        {
            using (var db = new FactoryModel())
            {
                var u = new User();

                u.UserName = name;
                u.UserAddress = address;
                u.UserEmail = email;

                db.Users.Add(u);
                db.SaveChanges();
                return u;
            }
        }
Exemplo n.º 3
0
        public static ChildCare CreateChildCare(string name, string address, string description)
        {
            using (var db = new FactoryModel())
            {
                var ch = new ChildCare();

                ch.ChildCareName = name;
                ch.ChildCareAddress = address;
                ch.ChildCareDescription = description;

                db.ChildCares.Add(ch);
                db.SaveChanges();
                return ch;
            }
        }
Exemplo n.º 4
0
 public static decimal RatingUpdate(FactoryModel db, int userID, int childCareID, int rating)
 {
     if (rating < 1 || rating > 5)
         return 0;
     var rate = db.ChildCares.Where(s => s.ChildCareID == childCareID).FirstOrDefault();
        if (rate.ChildCareRating == 0)
         {
             rate.ChildCareRating = rating;
         }
         else
         {
             rate.ChildCareRating = (rating + rate.ChildCareRating) / 2;
         }
         db.SaveChanges();
         return rate.ChildCareRating;
 }