private bool IsReservationConflicted(Reservation reservation)
 {
     var resInterval = new Interval(new Instant(reservation.Begin.Ticks), new Instant(reservation.End.Ticks));
     var existingIntervals =
         _db.Reservations.Where(r => r.ResourceId == reservation.ResourceId).ToList()
             .Select(r => new Interval(new Instant(r.Begin.Ticks), new Instant(r.End.Ticks)))
             .ToList();
     return existingIntervals.Any(i => Overlaps(i, resInterval));
 }
        // GET: Reservations/Create
        public ActionResult Create(int? resourceId)
        {
            if (resourceId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var resource = _db.Resources.Find(resourceId);

            var model = new Reservation
            {
                Resource = resource,
                Begin = DateTime.Now.ConvertToUserTime(),
                End = DateTime.Now.AddHours(3).ConvertToUserTime()
            };
            return View(model);
        }
Exemplo n.º 3
0
        public bool Seed(ApplicationDbContext context)
        {
#if DEBUG
            ApplicationRoleManager roleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(context));

            var success = CreateRole(roleManager, "Admin", "Global Access");
            if (!success)
            {
                return(false);
            }

            success = CreateRole(roleManager, "User", "Restricted to business domain activity");
            if (!success)
            {
                return(false);
            }

            ApplicationUserManager userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context));

            //admin
            ApplicationUser adminUser = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            userManager.Create(adminUser, "Demo123!");
            success = AddUserToRole(userManager, adminUser.Id, "Admin");

            //demoUser1
            var user = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            userManager.Create(user, "Demo123!");
            success = success && AddUserToRole(userManager, user.Id, "User");

            //demoUser2
            var user2 = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            userManager.Create(user2, "Demo123!");
            success = success && AddUserToRole(userManager, user2.Id, "User");

            //DemoResource1
            var resource = new Resource();
            resource.Name = "DemoResource1";
            context.Resources.Add(resource);

            //DemoResource2
            var resource2 = new Resource();
            resource2.Name = "DemoResource2";
            context.Resources.Add(resource2);

            //DemoReservation
            var reservation = new Reservation()
            {
                Resource = resource,
                Begin    = DateTime.Now,
                End      = DateTime.Now.AddYears(2),
                User     = user
            };
            context.Reservations.Add(reservation);
            context.SaveChanges();

            return(success);
#endif
#pragma warning disable 162
            // ReSharper disable once HeuristicUnreachableCode
            return(true);

#pragma warning restore 162
        }