Exemplo n.º 1
0
        public static UserCircle AddUserCircle(UserCircle newUserCircle)
        {
            using (var db = new MyCirclesEntityModel())
            {
                Circle existingCircle = db.Circles.Where(ec => ec.Id == newUserCircle.CircleId).FirstOrDefault();

                if (existingCircle == null)
                {
                    existingCircle = CircleDAO.AddCircle(newUserCircle.CircleId);
                }

                db.UserCircles.Add(newUserCircle);
                db.SaveChanges();

                return(newUserCircle);
            }
        }
Exemplo n.º 2
0
        public static void AddUserCircle(int userId, string circleName)
        {
            using (var db = new MyCirclesEntityModel())
            {
                UserCircle newUserCircle  = new UserCircle();
                Circle     existingCircle = db.Circles.Where(ec => ec.Id == circleName).FirstOrDefault();

                if (existingCircle == null)
                {
                    existingCircle = CircleDAO.AddCircle(circleName);
                }

                newUserCircle.CircleId = existingCircle.Id;
                newUserCircle.UserId   = userId;

                db.UserCircles.Add(newUserCircle);
                db.SaveChanges();
            }
        }