Esempio n. 1
0
        public async Task <ActionResult <ActiveMerchantMBE> > GetActiveMerchant()
        {
            await Task.Delay(100);

            return(Ok(new ActiveMerchantMBE
            {
                MerchantGuid = GeneralConstants.MERCHANT_1_GUID,
                MerchantName = @"Domino's Pizza",
                LogoUrl = HttpHelpers.BuildFullURL(this.Request, GeneralConstants.MERCHANT_1_LOGO_FILENAME),
                CatalogItems = new List <CatalogItemMBE>
                {
                    new CatalogItemMBE
                    {
                        ItemGuid = Guid.NewGuid(),
                        ItemName = "Product/Service 1",
                        ItemUnitPrice = 10.51M
                    },
                    new CatalogItemMBE
                    {
                        ItemGuid = Guid.NewGuid(),
                        ItemName = "Product/Service 2",
                        ItemUnitPrice = 20.52M
                    },
                    new CatalogItemMBE
                    {
                        ItemGuid = Guid.NewGuid(),
                        ItemName = "Product/Service 3",
                        ItemUnitPrice = 15.92M
                    }
                }
            }));
        }
Esempio n. 2
0
        public async Task <ActionResult <IEnumerable <MerchantMBE> > > GetAllMerchants()
        {
            // query the DB
            var dbMerchants = await _dbContext.GetAllMerchantsAsync();

            // if no results from DB, return an empty list
            if (dbMerchants == null)
            {
                return(Ok(new List <MerchantMBE>()));
            }

            // convert DB entities to the public entity types
            var merchants = dbMerchants.ConvertAll(dbM => (MerchantMBE)dbM);

            foreach (var merchant in merchants)
            {
                merchant.LogoUrl = (!string.IsNullOrEmpty(merchant.LogoFileName)) ? HttpHelpers.BuildFullURL(this.Request, merchant.LogoFileName) : null;
                var dbDemoCustomers = await _dbContext.GetDemoCustomersAsync(merchant.MerchantId);

                merchant.DemoCustomers = dbDemoCustomers.ConvertAll(dbDc => (DemoCustomerMBE)dbDc);
            }

            // return the response
            return(Ok(merchants));
        }
Esempio n. 3
0
        public async Task <ActionResult <MerchantMBE> > GetMerchant([FromRoute] Guid merchantGuid)
        {
            // query the DB
            var dbMerchant = await _dbContext.GetMerchantAndDemoCustomersAsync(merchantGuid);

            // if we did not find a matching merchant
            if (dbMerchant == null)
            {
                return(NotFound($"MerchantGuid: [{merchantGuid}] not found"));
            }

            // convert DB entity to the public entity type
            var merchant = (MerchantMBE)dbMerchant;

            merchant.LogoUrl = (!string.IsNullOrEmpty(merchant.LogoFileName)) ? HttpHelpers.BuildFullURL(this.Request, merchant.LogoFileName) : null;

            // create an empty working object
            var demoCustomers = new List <DemoCustomerMBE>();

            // optionally convert DB entities to the public entity type
            if (dbMerchant.DemoCustomers != null)
            {
                // convert DB entities to the public entity types
                demoCustomers = dbMerchant.DemoCustomers.ConvertAll(dbC => (DemoCustomerMBE)dbC);
            }

            // set the value of the property collection on the parent object
            merchant.DemoCustomers = demoCustomers;

            // return the response
            return(Ok(merchant));
        }
Esempio n. 4
0
        public async Task <ActionResult <MerchantMBE> > GetMerchant(Guid merchantGuid)
        {
            if (merchantGuid != GeneralConstants.MERCHANT_1_GUID)
            {
                return(NotFound($"Merchant with ID: {merchantGuid} not found"));
            }

            await Task.Delay(100);

            return(Ok(new MerchantMBE
            {
                MerchantGuid = GeneralConstants.MERCHANT_1_GUID,
                MerchantName = @"Domino's Pizza",
                MerchantUrl = new Uri("https://www.dominos.com"),
                LogoUrl = HttpHelpers.BuildFullURL(this.Request, GeneralConstants.MERCHANT_1_LOGO_FILENAME),
                IsSupportsTips = true,
                IsActive = true,
                DemoCustomers = new List <DemoCustomerMBE>()
                {
                    new DemoCustomerMBE
                    {
                        CustomerGuid = GeneralConstants.MERCHANT_1_CUSTOMER_1_GUID,
                        CustomerName = @"Joe Smith",
                        CustomerPhoneNo = @"(513) 456-7890"
                    },
                    new DemoCustomerMBE
                    {
                        CustomerGuid = GeneralConstants.MERCHANT_1_CUSTOMER_2_GUID,
                        CustomerName = @"Jane Doe",
                        CustomerPhoneNo = @"(513) 555-1212"
                    }
                }
            }));
        }
Esempio n. 5
0
        public async Task <ActionResult <IEnumerable <MerchantMBE> > > GetAllMerchants()
        {
            await Task.Delay(100);

            return(Ok(new List <MerchantMBE>
            {
                new MerchantMBE
                {
                    MerchantGuid = GeneralConstants.MERCHANT_1_GUID,
                    MerchantName = @"Domino's Pizza",
                    MerchantUrl = new Uri("https://www.dominos.com"),
                    LogoUrl = HttpHelpers.BuildFullURL(this.Request, GeneralConstants.MERCHANT_1_LOGO_FILENAME),
                    IsSupportsTips = true,
                    IsActive = true
                },
                new MerchantMBE
                {
                    MerchantGuid = GeneralConstants.MERCHANT_2_GUID,
                    MerchantName = @"Raising Cane's",
                    MerchantUrl = new Uri("https://www.raisingcanes.com"),
                    LogoUrl = HttpHelpers.BuildFullURL(this.Request, GeneralConstants.MERCHANT_2_LOGO_FILENAME),
                    IsSupportsTips = true,
                    IsActive = false
                }
            }));
        }
Esempio n. 6
0
        public async Task <ActionResult <CustomerOrderMBE> > GetCustomerOrder(Guid orderGuid)
        {
            //query the db
            var dbCustomerOrder = await _dbContext.GetOrderExplodedAsync(orderGuid);

            //if we do not find a matching order
            if (dbCustomerOrder == null)
            {
                return(NotFound($"Customer order: [{orderGuid}] not found"));
            }

            var customerOrder = (CustomerOrderMBE)dbCustomerOrder;

            customerOrder.LogoUrl     = HttpHelpers.BuildFullURL(this.Request, dbCustomerOrder.Merchant.LogoFileName);
            customerOrder.MerchantUrl = dbCustomerOrder.Merchant.MerchantUrl;

            return(Ok(customerOrder));
        }
Esempio n. 7
0
        public async Task <ActionResult <string> > UploadLogoImage([FromRoute] Guid merchantGuid, IFormFile imageFile)
        {
            // Step 1: Get the merchant
            var dbMerchant = await _dbContext.GetMerchantAsync(merchantGuid);

            // if we did not find a matching merchant
            if (dbMerchant == null)
            {
                return(BadRequest(new ArgumentException($"MerchantID: [{merchantGuid}] not found", nameof(merchantGuid))));
            }

            // Step 2: Validate supported image type and that image format in the file matches the extension
            (byte[] fileContents, string errorMessage) = ImageFileHelpers.ProcessFormFile(imageFile, _permittedExtensions, _fileSizeLimit);

            if (fileContents.Length == 0)
            {
                return(BadRequest(new ArgumentException(errorMessage, nameof(imageFile))));
            }

            // Step 3: Store in local folder
            string imageFileName = $"{merchantGuid}-logo{System.IO.Path.GetExtension(imageFile.FileName)}";
            // use Path.Combine to deal with O/S differences re Linux: "/" vs Windows: "\"
            string imageFilePathName = System.IO.Path.Combine(_environment.ContentRootPath,
                                                              GeneralConstants.LOGO_IMAGES_FOLDER_NAME,
                                                              imageFileName);

            using (var fileStream = System.IO.File.Create(imageFilePathName))
            {
                fileStream.Write(fileContents);
            }

            // Step 4: Update the merchant
            dbMerchant.LogoFileName = imageFileName;
            await _dbContext.UpdateMerchantAsync(dbMerchant);

            // Step 5: Return results        https://localhost:44318/LogoImages/f8c6f5b6-533e-455f-87a1-ced552898e1d.png
            var imageUri = HttpHelpers.BuildFullURL(this.Request, imageFileName);

            return(Ok(imageUri));
        }
Esempio n. 8
0
        public async Task <ActionResult <CustomerOrderMBE> > GetCustomerOrder([FromRoute] Guid orderGuid)
        {
            if (orderGuid != GeneralConstants.ORDER_1_GUID)
            {
                return(NotFound($"Customer order: [{orderGuid}] not found"));
            }

            await Task.Delay(100);

            return(Ok(new CustomerOrderMBE
            {
                OrderGuid = orderGuid,
                OrderId = 99,
                OrderStatus = Enums.ORDER_STATUS.SMS_Sent,
                MerchantName = @"Domino's Pizza",
                IsSupportsTips = true,
                LogoUrl = HttpHelpers.BuildFullURL(this.Request, GeneralConstants.MERCHANT_1_LOGO_FILENAME),
                CustomerName = "Joe Smith",
                CustomerPhoneNo = "(666) 666-6666",
                OrderSubTotal = 15.46M,
                OrderDateTimeUTC = DateTime.UtcNow
            }));
        }
Esempio n. 9
0
        public async Task <ActionResult <ActiveMerchantMBE> > GetActiveMerchant()
        {
            //Query the db for the active merchant
            var dbMerchant = await _dbContext.GetActiveMerchantAsync();

            if (dbMerchant == null)
            {
                return(NotFound($"Active merchant not found"));
            }

            //query the db for catalogue Items
            // 1st: look for unique catalog items for this merchant
            var dbCatalogueItems = await _dbContext.GetCatalogItemsAsync(dbMerchant.MerchantId);

            // 2nd: if the merchant did not have unique catalog items, use the default ones on merchantId = 0
            if (dbCatalogueItems == null || dbCatalogueItems.Count == 0)
            {
                dbCatalogueItems = await _dbContext.GetCatalogItemsAsync(0);
            }

            // query the db for demo customers
            var dbDemoCustomers = await _dbContext.GetDemoCustomersAsync(dbMerchant.MerchantId);

            // build the return object
            var activeMerchant = new ActiveMerchantMBE
            {
                MerchantGuid  = dbMerchant.MerchantGuid,
                MerchantName  = dbMerchant.MerchantName,
                LogoUrl       = HttpHelpers.BuildFullURL(this.Request, dbMerchant.LogoFileName),
                CatalogItems  = dbCatalogueItems.ConvertAll(dbCI => (CatalogItemMBE)dbCI),
                DemoCustomers = dbDemoCustomers.ConvertAll(dbDC => (DemoCustomerMBE)dbDC)
            };

            // return the response,
            return(Ok(activeMerchant));
        }