Beispiel #1
0
 public async Task <IList <Customer> > GetAsync()
 {
     using (var context = DiResolver.Resolve <IHotelContext>())
     {
         return(await context.Customers.AsQueryable().ToListAsync());
     }
 }
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();

            // lazy load DI.
            var logger = ModuleLoader.DI.Get <ILog>(Constants.ServerLoggerName);

            var diResolver = new DiResolver(ModuleLoader.DI);

            DependencyResolver.SetResolver(diResolver);                        // MVC
            GlobalConfiguration.Configuration.DependencyResolver = diResolver; // WebAPI

            // To resolve self referencing loop error.
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Re‌ferenceLoopHandling = ReferenceLoopHandling.Ignore;

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration, logger);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters, logger);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configuration.EnsureInitialized();

            EmailEngine.Logger(logger);
        }
Beispiel #3
0
 public async Task DeleteAsync(Guid id)
 {
     using (var context = DiResolver.Resolve <IExampleDomainContext>())
     {
         context.Examples.Delete(e => e.Id == id);
         await context.ApplyChangesAsync();
     }
 }
Beispiel #4
0
 public async Task AddAsync(Hotel hotel)
 {
     using (var context = DiResolver.Resolve <IHotelContext>())
     {
         context.Hotels.Add(hotel);
         await context.ApplyChangesAsync();
     }
 }
Beispiel #5
0
        //private bool NameIsUnique(IHotelContext context, string name)
        //{
        //    var recs = context.Hotels.AsQueryable().Count(h => name.Trim().ToLower() == h.HotelName.Trim().ToLower());
        //    return recs == 0;
        //}

        public async Task DeleteAsync(int id)
        {
            using (var context = DiResolver.Resolve <IHotelContext>())
            {
                context.Reservaitions.Delete(e => e.ReservationId == id);
                await context.ApplyChangesAsync();
            }
        }
Beispiel #6
0
 public async Task AddAsync(Customer customer)
 {
     using (var context = DiResolver.Resolve <IHotelContext>())
     {
         context.Customers.Add(customer);
         await context.ApplyChangesAsync();
     }
 }
Beispiel #7
0
 public async Task AddAsync(ExampleModel exampleModel)
 {
     using (var context = DiResolver.Resolve <IExampleDomainContext>())
     {
         context.Examples.Add(exampleModel);
         await context.ApplyChangesAsync();
     }
 }
Beispiel #8
0
 public async Task AddAsync(Reservation reservation)
 {
     using (var context = DiResolver.Resolve <IHotelContext>())
     {
         context.Reservaitions.Add(reservation);
         await context.ApplyChangesAsync();
     }
 }
Beispiel #9
0
 public async Task AddAsync(Room room)
 {
     using (var context = DiResolver.Resolve <IHotelContext>())
     {
         context.Rooms.Add(room);
         await context.ApplyChangesAsync();
     }
 }
Beispiel #10
0
        public async Task <IList <Reservation> > GetAsync()
        {
            using (var context = DiResolver.Resolve <IHotelContext>())
            {
                var rm = await context.Reservaitions.AsQueryable()
                         .ToListAsync();

                return(rm);
            }
        }
Beispiel #11
0
        public async Task <IList <Reservation> > GetAsync(DateTime date)
        {
            using (var context = DiResolver.Resolve <IHotelContext>())
            {
                var rm = await context.Reservaitions.AsQueryable()
                         .Where(rv => rv.ReservedFrom <= date && rv.ReservedTo >= date)
                         .ToListAsync();

                return(rm);
            }
        }
Beispiel #12
0
        private async Task <IList <ExampleModel> > Get(IList <Guid> ids)
        {
            List <ExampleModel> result;

            using (var context = DiResolver.Resolve <IExampleDomainContext>())
            {
                result = await context.Examples.AsQueryable().Where(ent => ids.Contains(ent.Id)).ToListAsync();
            }

            return(result);
        }
Beispiel #13
0
        public async Task <IList <Room> > GetAsync()
        {
            using (var context = DiResolver.Resolve <IHotelContext>())
            {
                var rm = await context.Rooms.AsQueryable()
                         .Include(b => b.RoomBeds)
                         .Include(b => b.Reservations)
                         .ToListAsync();

                return(rm);
            }
        }
Beispiel #14
0
        public async Task UpdateAsync(Reservation reservation)
        {
            using (var context = DiResolver.Resolve <IHotelContext>())
            {
                var existing = await context.Reservaitions.AsQueryable().SingleOrDefaultAsync(x => x.ReservationId == reservation.ReservationId);

                if (existing == null)
                {
                    throw new KeyNotFoundException($"No record found with {nameof(Reservation.ReservationId)} {reservation.ReservationId}");
                }

                existing.InjectFrom(reservation);
                await context.ApplyChangesAsync();
            }
        }
Beispiel #15
0
        public async Task UpdateAsync(Customer customer)
        {
            using (var context = DiResolver.Resolve <IHotelContext>())
            {
                var existing = await context.Customers.AsQueryable().SingleOrDefaultAsync(x => x.CustomerId == customer.CustomerId);

                if (existing == null)
                {
                    throw new KeyNotFoundException($"No record found with {nameof(customer.CustomerId)} {customer.CustomerId}");
                }

                existing.InjectFrom(customer);
                await context.ApplyChangesAsync();
            }
        }
Beispiel #16
0
        public async Task UpdateAsync(ExampleModel exampleModel)
        {
            using (var context = DiResolver.Resolve <IExampleDomainContext>())
            {
                var existing = await context.Examples.AsQueryable().SingleOrDefaultAsync(x => x.Id == exampleModel.Id);

                if (existing == null)
                {
                    throw new KeyNotFoundException($"No record found with {nameof(exampleModel.Id)} {exampleModel.Id}");
                }

                existing.InjectFrom(exampleModel);
                await context.ApplyChangesAsync();
            }
        }
Beispiel #17
0
        public async Task <IList <Room> > GetAsync(DateTime from, DateTime to)
        {
            using (var context = DiResolver.Resolve <IHotelContext>())
            {
                var rm = await context.Rooms.AsQueryable()
                         .Include(b => b.RoomBeds)
                         .Include(b => b.Reservations)
                         .Where(r => (r.Reservations.Count == 0) ||
                                (!r.Reservations.Any(rv =>
                                                     (rv.ReservedTo >= from && rv.ReservedFrom <= to))))
                         .ToListAsync();

                return(rm);
            }
        }
Beispiel #18
0
        /// <summary>
        ///     驗証是否符合 CustomAuthorizeAttribute 資格
        /// </summary>
        private void ValidateCustomAuthorize(ControllerContext controllerContext, string actionName)
        {
            var controllerDescriptor = GetControllerDescriptor(controllerContext);

            var actionDescriptor = FindAction(controllerContext, controllerDescriptor, actionName)
                                   ?? controllerDescriptor.GetCanonicalActions()
                                   .FirstOrDefault(a => a.ActionName == actionName);

            var attributeRoles = controllerDescriptor.GetControllerCustomAttributes()
                                 .Concat(actionDescriptor.GetActionCustomAttributes())
                                 .Distinct()
                                 .ToArray();

            if (attributeRoles.Length > 0 == false)
            {
                return;
            }

            if (_userDto == null)
            {
                throw new CustomException("No Authentication")
                      {
                          ErrorCode = HttpStatusCode.Unauthorized
                      };
            }

            var authorizeRepository = DiResolver.GetService <IAuthorizeRepository>();
            var dto = new AuthorizationDto
            {
                UserId         = _userDto.UserId,
                AttributeRoles = attributeRoles
            };

            if (authorizeRepository.Auth(dto) == false)
            {
                throw new CustomException("Authorizted Failed")
                      {
                          ErrorCode       = HttpStatusCode.Unauthorized,
                          IsAuthenticated = _userDto != null
                      };
            }
        }