public async Task <BaseServiceResponse <CustomerDto> > GetCustomerAccount(string macAddress)
        {
            BaseServiceResponse <CustomerDto> response = new BaseServiceResponse <CustomerDto>();

            try
            {
                var existing = await _dbContext.Customers.Where(e => e.MacAddress == macAddress).SingleOrDefaultAsync();

                if (existing != null)
                {
                    response.Results = new CustomerDto()
                    {
                        Id         = existing.Id,
                        Name       = existing.Name ?? "",
                        Address    = existing.Address ?? "",
                        MacAddress = existing.MacAddress
                    };

                    response.Success = true;
                }
                else
                {
                    //new customer
                    CustomerEntity entity = new CustomerEntity()
                    {
                        MacAddress = macAddress,
                        Created    = DateTime.Now
                    };

                    _dbContext.Customers.Add(entity);
                    await _dbContext.SaveChangesAsync();

                    response.Results = new CustomerDto()
                    {
                        MacAddress = entity.MacAddress,
                        Id         = entity.Id
                    };

                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Customer Service Exception - Get Customer Account");
                response.Success      = false;
                response.ErrorMessage = ex.ToString();
            }

            return(response);
        }
Exemple #2
0
        private async Task <bool> AddDemoData()
        {
            try
            {
                List <CarpetPropertyEntity>     props   = new List <CarpetPropertyEntity>();
                List <CarpetColourPalletEntity> colours = new List <CarpetColourPalletEntity>();

                CarpetEntity carpet = new CarpetEntity()
                {
                    Name        = "Empress Carpet",
                    Description =
                        "The Empress carpet is available in a wide range of bleach cleanable colours, making it suitable for all areas around the home excluding bathrooms. Action backed for added comfort underfoot, Empress Carpet carries a 15-year wear warranty and 20-year stain warranty.",
                    PetFriendly = false,
                    PriceM2     = Convert.ToDecimal(22.50),
                };


                _dbContext.Carpets.Add(carpet);
                await _dbContext.SaveChangesAsync();

                props.Add(new CarpetPropertyEntity()
                {
                    BulletPoint = "Bleach cleanable carpet",
                    CarpetId    = carpet.Id
                });

                props.Add(new CarpetPropertyEntity()
                {
                    BulletPoint = "Suitable for all rooms excluding bathrooms",
                    CarpetId    = carpet.Id
                });

                props.Add(new CarpetPropertyEntity()
                {
                    BulletPoint = "15 - year wear warranty",
                    CarpetId    = carpet.Id
                });

                props.Add(new CarpetPropertyEntity()
                {
                    BulletPoint = "20 year stain warranty",
                    CarpetId    = carpet.Id
                });

                props.Add(new CarpetPropertyEntity()
                {
                    BulletPoint = " 100 % polypropylene",
                    CarpetId    = carpet.Id
                });

                carpet.Propertys = props;



                List <CarpetImageEntity> images = new List <CarpetImageEntity>();

                images.Add(new CarpetImageEntity()
                {
                    ImageType     = CarpetImageType.MainImage,
                    ImageName     = "Main Image",
                    Link          = "default.png",
                    AlternateText = "Default Image",
                    CarpetId      = carpet.Id
                });

                carpet.Images = images;

                carpet.Options = new List <CarpetSizeOptionEntity>();

                carpet.Options.Add(new CarpetSizeOptionEntity()
                {
                    Width    = 3,
                    Length   = 4,
                    M2       = 20,
                    CarpetId = carpet.Id
                });

                carpet.Options.Add(new CarpetSizeOptionEntity()
                {
                    Width    = 5,
                    Length   = 4,
                    M2       = 35,
                    CarpetId = carpet.Id
                });

                carpet.Options.Add(new CarpetSizeOptionEntity()
                {
                    Width    = 6,
                    Length   = 4,
                    M2       = 45,
                    CarpetId = carpet.Id
                });

                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }