示例#1
0
        private async Task <IActionResult> Delete(int venueId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanAdministerCompany)
            {
                return(RedirectToPage("/Index"));
            }

            var getResult = (await venues.FetchVenue(venueId).ConfigureAwait(false))
                            .Ensure(e => e.HasValue, "Venue found")
                            .OnSuccess(e => e.Value);

            if (!getResult.IsSuccess)
            {
                return(RedirectToPage("/Index"));
            }

            var result = await venues.DropVenue(venueId).ConfigureAwait(false);

            if (result.IsSuccess)
            {
                return(RedirectToPage("/CompanyVenues", new
                {
                    companyId = getResult.Value.CompanyId
                }));
            }
            else
            {
                return(RedirectToPage("/Index"));
            }
        }
示例#2
0
        private async Task <bool> FetchData(int venueId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            ProductTypes = await productTypes.FetchProductTypes(0, int.MaxValue)
                           .Ensure(t => t.HasValue, "Product Types were found")
                           .OnSuccess(t => t.Value)
                           .OnBoth(t => t.IsSuccess ? t.Value : new List <ProductType>())
                           .ConfigureAwait(false);

            if (Role.CanAdministerSystem)
            {
                return(true);
            }

            var venue = await venues.FetchVenue(venueId)
                        .Ensure(t => t.HasValue, "Venue was found")
                        .OnSuccess(t => t.Value)
                        .ConfigureAwait(false);

            if (!venue.IsSuccess)
            {
                return(false);
            }

            if (!Role.CanAdministerVenue || Employee.CompanyId != venue.Value.CompanyId)
            {
                return(false);
            }

            return(true);
        }
示例#3
0
        private async Task <bool> FetchData(int menuId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanWorkWithVenue)
            {
                return(false);
            }

            var result = (await menus.FetchFullMenu(menuId).ConfigureAwait(false))
                         .Ensure(e => e.HasValue, "Menu found")
                         .OnSuccess(e => e.Value);

            Menu = result.IsSuccess ? result.Value : null;

            var menuVenue = (await venues.FetchVenue(Menu.VenueId).ConfigureAwait(false))
                            .Ensure(e => e.HasValue, "Venue found")
                            .OnSuccess(e => e.Value);

            if (menuVenue.IsFailure)
            {
                return(false);
            }

            if (!Role.CanAdministerSystem && menuVenue.Value.CompanyId != Employee.CompanyId)
            {
                return(false);
            }

            ViewData["SubnavVenueId"] = Menu.VenueId;
            Title = Menu.MenuName;
            return(result.IsSuccess);
        }
示例#4
0
        private async Task <bool> FetchData(int productId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanAdministerVenue)
            {
                return(false);
            }

            ProductTypes = await productTypes.FetchProductTypes(0, int.MaxValue)
                           .Ensure(t => t.HasValue, "Product Types were found")
                           .OnSuccess(t => t.Value)
                           .OnBoth(t => t.IsSuccess ? t.Value : new List <ProductType>())
                           .ConfigureAwait(false);

            var product = (await products.FetchProduct(productId).ConfigureAwait(false))
                          .Ensure(e => e.HasValue, "Product found")
                          .OnSuccess(e => e.Value);

            if (product.IsFailure)
            {
                return(false);
            }

            var venue = await venues.FetchVenue(product.Value.VenueId)
                        .Ensure(t => t.HasValue, "Venue was found")
                        .OnSuccess(t => t.Value)
                        .ConfigureAwait(false);

            if (!venue.IsSuccess)
            {
                return(false);
            }

            if (!Role.CanAdministerSystem && Employee.CompanyId != venue.Value.CompanyId)
            {
                return(false);
            }

            Title = product.Value.ProductName;

            Input ??= new InputModel
            {
                ProductName        = product.Value.ProductName,
                ProductTypeId      = product.Value.ProductType.ToString(),
                ProductDescription = product.Value.ProductDescription,
                Price         = product.Value.Price,
                AgeRestricted = product.Value.AgeRestricted,
            };

            return(true);
        }
示例#5
0
        private async Task <bool> FetchData(int menuId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            var result = (await menus.FetchFullMenu(menuId).ConfigureAwait(false))
                         .Ensure(e => e.HasValue, "Menu found")
                         .OnSuccess(e => e.Value);

            if (result.IsFailure)
            {
                return(false);
            }

            VenueId = result.Value.VenueId;

            Products = await products.FetchVenueProducts(VenueId, 0, int.MaxValue)
                       .Ensure(t => t.HasValue, "Venue products were found")
                       .OnSuccess(t => t.Value)
                       .OnBoth(t => t.IsSuccess ? t.Value : new List <Product>())
                       .ConfigureAwait(false);

            ProductMap = new Dictionary <int, Product>();
            foreach (var product in Products)
            {
                ProductMap[product.ProductId] = product;
            }

            var venue = await venues.FetchVenue(VenueId)
                        .Ensure(t => t.HasValue, "Venue was found")
                        .OnSuccess(t => t.Value)
                        .ConfigureAwait(false);

            if (!venue.IsSuccess)
            {
                return(false);
            }

            if (!Role.CanAdministerSystem && (!Role.CanAdministerVenue || Employee.CompanyId != venue.Value.CompanyId))
            {
                return(false);
            }

            Title = result.Value.MenuName;
            Input ??= new InputModel {
                MenuName        = result.Value.MenuName,
                ProductIds      = result.Value.Products.Select(p => p.ProductId.ToString()).ToList(),
                MenuDescription = result.Value.MenuDescription
            };

            return(true);
        }
示例#6
0
        public async Task <IActionResult> DropVenue([FromRoute(Name = "venueId")] int venueId)
        {
            var venue = await venues.FetchVenue(venueId).ConfigureAwait(false);

            if (venue.IsFailure || venue.Value.HasNoValue)
            {
                return(NotFound());
            }

            var ven = venue.Value.Value;

            if (this.GetAuthContext().Employee.Value.CompanyId != ven.CompanyId && !this.GetAuthContext().EmployeeRole.Value.CanAdministerSystem)
            {
                return(Unauthorized());
            }

            return(await venues.DropVenue(venueId)
                   .OnBoth(v => v.IsFailure ? StatusCode(404) : StatusCode(200))
                   .ConfigureAwait(false));
        }
示例#7
0
        private async Task <bool> FetchData(int productId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanWorkWithVenue)
            {
                return(false);
            }

            var result = (await products.FetchProduct(productId).ConfigureAwait(false))
                         .Ensure(e => e.HasValue, "Product found")
                         .OnSuccess(e => e.Value);

            Product = result.IsSuccess ? result.Value : null;

            var productVenue = (await venues.FetchVenue(Product.VenueId).ConfigureAwait(false))
                               .Ensure(e => e.HasValue, "Venue found")
                               .OnSuccess(e => e.Value);

            var result2 = (await productTypes.FetchProductType(Product.ProductType).ConfigureAwait(false))
                          .Ensure(e => e.HasValue, "Product type found")
                          .OnSuccess(e => e.Value);

            ProductType = result2.IsSuccess ? result2.Value.ProductTypeName : null;

            if (productVenue.IsFailure)
            {
                return(false);
            }

            if (!Role.CanAdministerSystem && productVenue.Value.CompanyId != Employee.CompanyId)
            {
                return(false);
            }

            ViewData["SubnavVenueId"] = Product.VenueId;
            Title = Product.ProductName;
            return(result.IsSuccess);
        }
示例#8
0
        private async Task <bool> FetchData(int venueId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            Products = await products.FetchVenueProducts(venueId, 0, int.MaxValue)
                       .Ensure(t => t.HasValue, "Venue products were found")
                       .OnSuccess(t => t.Value)
                       .OnBoth(t => t.IsSuccess ? t.Value : new List <Product>())
                       .ConfigureAwait(false);

            ProductMap = new Dictionary <int, Product>();
            foreach (var product in Products)
            {
                ProductMap[product.ProductId] = product;
            }

            if (Role.CanAdministerSystem)
            {
                return(true);
            }

            var venue = await venues.FetchVenue(venueId)
                        .Ensure(t => t.HasValue, "Venue was found")
                        .OnSuccess(t => t.Value)
                        .ConfigureAwait(false);

            if (!venue.IsSuccess)
            {
                return(false);
            }

            if (!Role.CanAdministerVenue || Employee.CompanyId != venue.Value.CompanyId)
            {
                return(false);
            }

            return(true);
        }
示例#9
0
        private async Task <bool> FetchData(int venueId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanAdministerSystem && Employee.VenueId != venueId)
            {
                return(false);
            }

            if (Role.CanAdministerVenue || Role.CanWorkWithVenue)
            {
                var venue = (await venues.FetchVenue(venueId).ConfigureAwait(false))
                            .Ensure(e => e.HasValue, "Venue found")
                            .OnSuccess(e => e.Value);

                if (venue.IsFailure)
                {
                    return(false);
                }

                Venue = venue.Value;

                var venueTags = (await tags.FetchVenueTags(venue.Value.VenueId).ConfigureAwait(false))
                                .Ensure(e => e.HasValue, "Venue tags found")
                                .OnSuccess(e => e.Value);

                if (venueTags.IsFailure)
                {
                    return(false);
                }

                Title = venue.Value.VenueName;

                Images = await images.FetchCompanyImages(venue.Value.CompanyId, 0, int.MaxValue)
                         .Ensure(i => i.HasValue, "Images were found")
                         .OnSuccess(i => (List <MediaImage>)i.Value.Select(image => new MediaImage
                {
                    ImageId    = image.ImageId,
                    ImageKey   = image.ImageKey,
                    CompanyId  = image.CompanyId,
                    ImageTitle = image.ImageTitle,
                    ImageUrl   = new Uri($"https://s3-eu-west-1.amazonaws.com/{settings.Connection.S3BucketName}/images/{image.CompanyId}__{image.ImageKey}__img"),
                }).ToList())
                         .OnBoth((Result <List <MediaImage> > i) => i.IsSuccess ? i.Value : new List <MediaImage>())
                         .ConfigureAwait(false);

                Documents = await documents.FetchCompanyDocuments(venue.Value.CompanyId, 0, int.MaxValue)
                            .Ensure(i => i.HasValue, "Documents were found")
                            .OnSuccess(i => i.Value)
                            .OnBoth((Result <List <Document> > i) => i.IsSuccess ? i.Value : new List <Document>())
                            .ConfigureAwait(false);

                DocumentLookup = new Dictionary <int, Document>();
                Documents.ForEach(doc => DocumentLookup[doc.DocumentId] = doc);

                var venueDocs = await venueDocuments.FetchVenueVenueDocuments(venueId, 0, int.MaxValue)
                                .Ensure(i => i.HasValue, "Venue Documents were found")
                                .OnSuccess(i => i.Value)
                                .OnBoth((Result <List <VenueDocument> > i) => i.IsSuccess ? i.Value : new List <VenueDocument>())
                                .ConfigureAwait(false);

                var openingTimes = await venueOpeningTimes.FetchVenueVenueOpeningTimes(venue.Value.VenueId)
                                   .Ensure(o => o.HasValue, "Opening times were found")
                                   .OnSuccess(o => o.Value)
                                   .OnBoth(o => o.IsSuccess ? o.Value : new List <VenueOpeningTime>())
                                   .ConfigureAwait(false);

                VenueOpeningTime sundayTime    = null;
                VenueOpeningTime mondayTime    = null;
                VenueOpeningTime tuesdayTime   = null;
                VenueOpeningTime wednesdayTime = null;
                VenueOpeningTime thursdayTime  = null;
                VenueOpeningTime fridayTime    = null;
                VenueOpeningTime saturdayTime  = null;

                foreach (var openingTime in openingTimes)
                {
                    switch (openingTime.DayOfWeek)
                    {
                    case 0:
                        sundayTime = openingTime;
                        break;

                    case 1:
                        mondayTime = openingTime;
                        break;

                    case 2:
                        tuesdayTime = openingTime;
                        break;

                    case 3:
                        wednesdayTime = openingTime;
                        break;

                    case 4:
                        thursdayTime = openingTime;
                        break;

                    case 5:
                        fridayTime = openingTime;
                        break;

                    case 6:
                        saturdayTime = openingTime;
                        break;
                    }
                }

                Input ??= new InputModel
                {
                    VenueName                   = venue.Value.VenueName,
                    VenueAddress                = venue.Value.VenueAddress,
                    VenueAddress2               = venue.Value.VenueAddress2,
                    VenueAddress3               = venue.Value.VenueAddress3,
                    VenueCounty                 = venue.Value.VenueCounty,
                    VenuePostCode               = venue.Value.VenuePostCode,
                    VenueContact                = venue.Value.VenueContact,
                    VenuePhone                  = venue.Value.VenuePhone,
                    VenueDescription            = venue.Value.VenueDescription,
                    ImageId                     = venue.Value.ImageId == null ? null : venue.Value.ImageId.ToString(),
                    Tags                        = string.Join(',', venueTags.Value.Select(t => t.TagName).ToList()),
                    DocumentIds                 = venueDocs.Select(id => id.DocumentId.ToString()).ToList(),
                    VenueProgress               = venue.Value.Progress,
                    ServingType                 = venue.Value.ServingType,
                    SundayOpeningTimeEnabled    = sundayTime != null,
                    SundayOpeningTimeStart      = sundayTime?.StartTime,
                    SundayOpeningTimeEnd        = sundayTime?.EndTime,
                    MondayOpeningTimeEnabled    = mondayTime != null,
                    MondayOpeningTimeStart      = mondayTime?.StartTime,
                    MondayOpeningTimeEnd        = mondayTime?.EndTime,
                    TuesdayOpeningTimeEnabled   = tuesdayTime != null,
                    TuesdayOpeningTimeStart     = tuesdayTime?.StartTime,
                    TuesdayOpeningTimeEnd       = tuesdayTime?.EndTime,
                    WednesdayOpeningTimeEnabled = wednesdayTime != null,
                    WednesdayOpeningTimeStart   = wednesdayTime?.StartTime,
                    WednesdayOpeningTimeEnd     = wednesdayTime?.EndTime,
                    ThursdayOpeningTimeEnabled  = thursdayTime != null,
                    ThursdayOpeningTimeStart    = thursdayTime?.StartTime,
                    ThursdayOpeningTimeEnd      = thursdayTime?.EndTime,
                    FridayOpeningTimeEnabled    = fridayTime != null,
                    FridayOpeningTimeStart      = fridayTime?.StartTime,
                    FridayOpeningTimeEnd        = fridayTime?.EndTime,
                    SaturdayOpeningTimeEnabled  = saturdayTime != null,
                    SaturdayOpeningTimeStart    = saturdayTime?.StartTime,
                    SaturdayOpeningTimeEnd      = saturdayTime?.EndTime,
                };

                return(true);
            }

            return(false);
        }