Пример #1
0
        public async Task <int> AddMakerIfNew(MakerMessage makerMessage)
        {
            var dbContextOptions = Step1Model.GetDbContextOptions();
            var mainDbContext    = Step1Model.GetDbContextFromOptions(dbContextOptions);

            var matchingMakers = mainDbContext.Makers
                                 .Where(x => x.Email == makerMessage.Email);

            var emailExists = (matchingMakers.Count() > 0);

            if (emailExists)
            {
                Console.WriteLine("Maker email already in database, not adding.");
                return(matchingMakers.First().ID);
            }

            var makerEntity = new Entities.Maker
            {
                Name  = makerMessage.Name,
                Email = makerMessage.Email
            };

            mainDbContext.Add(entity: makerEntity);

            await mainDbContext.SaveChangesAsync();

            return(makerEntity.ID);
        }
Пример #2
0
        public async Task <int> PaddleCount()
        {
            var dbContextOptions = Step1Model.GetDbContextOptions();
            var mainDbContext    = Step1Model.GetDbContextFromOptions(dbContextOptions);

            var nPaddles = await mainDbContext.Paddles
                           .CountAsync();

            // await mainDbContext.SaveChangesAsync();

            return(nPaddles);
        }
Пример #3
0
        public async Task <int> MakerCount()
        {
            var dbContextOptions = Step1Model.GetDbContextOptions();
            var mainDbContext    = Step1Model.GetDbContextFromOptions(dbContextOptions);

            var nMakers = await mainDbContext.Makers
                          .CountAsync();

            // await mainDbContext.SaveChangesAsync();

            return(nMakers);
        }
Пример #4
0
        public async Task <int> AddPaddleDimensionsIfNew(PaddleDimensionsMessage paddleDimensionsMessage)
        {
            var dbContextOptions = Step1Model.GetDbContextOptions();
            var mainDbContext    = Step1Model.GetDbContextFromOptions(dbContextOptions);

            var matchingPaddleDimensions = mainDbContext.PaddleDimensions
                                           .Where(x => (x.LengthCm == paddleDimensionsMessage.LengthCm &&
                                                        x.LoomDepthCm == paddleDimensionsMessage.LoomDepthCm &&
                                                        x.LoomHeightCm == paddleDimensionsMessage.LoomHeightCm &&
                                                        x.LoomLengthCm == paddleDimensionsMessage.LoomLengthCm &&
                                                        x.ShoulderLengthCm == paddleDimensionsMessage.ShoulderLengthCm &&
                                                        x.WidthCm == paddleDimensionsMessage.WidthCm &&
                                                        x.TipDepthCm == paddleDimensionsMessage.TipDepthCm));

            var paddleDimensionsExist = (matchingPaddleDimensions.Count() > 0);

            if (paddleDimensionsExist)
            {
                Console.WriteLine("Matching dimensions already in database, not adding.");
                return(matchingPaddleDimensions.First().ID);
            }

            var paddleDimensionEntity = new Entities.PaddleDimension
            {
                WidthCm          = paddleDimensionsMessage.WidthCm,
                LengthCm         = paddleDimensionsMessage.LengthCm,
                LoomHeightCm     = paddleDimensionsMessage.LoomHeightCm,
                LoomLengthCm     = paddleDimensionsMessage.LoomLengthCm,
                LoomDepthCm      = paddleDimensionsMessage.LoomDepthCm,
                TipDepthCm       = paddleDimensionsMessage.TipDepthCm,
                ShoulderLengthCm = paddleDimensionsMessage.ShoulderLengthCm,
            };

            mainDbContext.Add(entity: paddleDimensionEntity);

            await mainDbContext.SaveChangesAsync();

            return(paddleDimensionEntity.ID);
        }
Пример #5
0
        public async Task <IActionResult> OnPostPaddle([FromBody] PaddleMessage paddleMessage)
        {
            var makerID            = this.AddMakerIfNew(paddleMessage.makerMessage).Result;
            var paddleDimensionsID = this.AddPaddleDimensionsIfNew(paddleMessage.paddleDimensionsMessage).Result;

            var dbContextOptions = Step1Model.GetDbContextOptions();
            var mainDbContext    = Step1Model.GetDbContextFromOptions(dbContextOptions);

            var paddleEntity = new Entities.Paddle
            {
                ScaleFactor       = 1.0,
                MakerID           = makerID,
                PaddleDimensionID = paddleDimensionsID,
                DateCreated       = DateTime.UtcNow
            };

            mainDbContext.Add(entity: paddleEntity);

            await mainDbContext.SaveChangesAsync();

            return(new ObjectResult(paddleEntity.ID));
        }