public ActionResult Create(CreateEventViewModel model)
        {
            if (ModelState.IsValid)
            {
                var ev = CreateEventViewModel.ToEvent(model, this);
                this.Data.Events.Add(ev);
                this.Data.SaveChanges();

                string url = Url.Action("UserCalendar", "Events");
                return(Json(new { success = true, url = url }));
            }

            return(PartialView("_CreateEvent", model));
        }
Exemple #2
0
        public void CreateEventViewModelToEventMethodShouldReturnCorrectEventProperties()
        {
            var userList = new List <ApplicationUser>
            {
                new ApplicationUser {
                    Id = null, Addresses = new List <Address> {
                        new Address()
                    }
                }
            };

            var usersRepoMock = new Mock <IRepository <ApplicationUser> >(MockBehavior.Strict);

            usersRepoMock.Setup(x => x.All()).Returns(userList.AsQueryable());

            var uowDataMock = new Mock <IUowData>(MockBehavior.Strict);

            uowDataMock.Setup(x => x.Users).Returns(usersRepoMock.Object);

            var controller = new EventsController(uowDataMock.Object);

            var model = new CreateEventViewModel
            {
                EndDate   = new DateTime(2014, 12, 14),
                EndTime   = new DateTime(2014, 12, 14, 12, 0, 0),
                EventType = EventType.Single,
                StartDate = new DateTime(2014, 12, 13),
                StartTime = new DateTime(2014, 12, 13, 10, 30, 0),
            };

            var ev = CreateEventViewModel.ToEvent(model, controller);

            Assert.AreEqual(model.EndDate, ev.EndDateTime.Date);
            Assert.AreEqual(model.EndTime.ToShortTimeString(), ev.EndDateTime.ToShortTimeString());
            Assert.AreEqual(model.EventType, ev.EventType);
            Assert.AreEqual(model.StartDate, ev.StartDateTime.Date);
            Assert.AreEqual(model.StartTime.ToShortTimeString(), ev.StartDateTime.ToShortTimeString());
        }