Ejemplo n.º 1
0
        public ActionResult Create(CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = UserInfo.Id;

                var instance = new Instance
                {
                    Name = model.Name.Trim(),
                    Started = model.Started,
                    Closed = model.Closed,
                    Users = new List<User>()
                };

                DB.Save(db => {
                    var user = db.Users.Find(userId);
                    instance.Users.Add(user);
                    db.Instances.Add(instance);
                });

                return RedirectToAction("Details", new { id = instance.Id });

            }
            return View(model);
        }
Ejemplo n.º 2
0
        public void Users_GET_NotMember_ShouldGetException()
        {
            var user = new User { UserId = 12 };
            var instance = new Instance { Started = DateTime.Now };

            InitDb(db =>
            {
                db.Users.Add(user);
                db.Instances.Add(instance);

                db.SaveChanges();
            });

            var controller = new InviteController();
            controller.UserInfo = new UserInfo { Id = 12 };

            var data = DataFromView<InviteViewModel>(controller.Users(instance.Id));
        }
        public void Index_ReturnsInstancesThatBelongsToTheUser()
        {
            var user = new User { UserId = 12 };
            var instanceA = new Instance{Name = "A", Started = DateTime.Parse("2010-01-01"), Users = new List<User>{ user } };
            var instanceB = new Instance { Name = "B", Started = DateTime.Parse("2011-01-01"), Closed = DateTime.Parse("2012-01-01"), Users = new List<User> { user } };
            var instanceC = new Instance { Name = "C", Started = DateTime.Parse("2012-01-01"), Users = new List<User> { user } };
            var instanceD = new Instance{Name = "D", Started = DateTime.Parse("2012-01-01") };

            InitDb(db =>
            {
                db.Users.Add(user);
                db.Instances.Add(instanceA);
                db.Instances.Add(instanceB);
                db.Instances.Add(instanceC);
                db.Instances.Add(instanceD);
            });

            var controller = new InstanceController();
            controller.UserInfo = new UserInfo { Id = 12 };
            var data = DataFromView<IndexViewModel>(controller.Index());

            Assert.AreEqual(3, data.Instances.Count());
            Assert.IsFalse(data.Instances.Any(i => i.Name == "D"));
        }
Ejemplo n.º 4
0
        private Instance InitWithSingleMember()
        {
            var user = new User { UserId = 12 };
            var instance = new Instance { Started = DateTime.Now, Name = "Name", Users = new List<User> { user } };

            InitDb(db =>
            {
                db.Users.Add(user);
                db.Instances.Add(instance);

                db.SaveChanges();
            });
            return instance;
        }