public async Task <CreatePropertyPayload> CreateProperty(CreatePropertyInput input,
                                                                 [ScopedService] TenantFileContext context)

        {
            var property = new Property
            {
                Name = input.Name
                ,
                Address = new Address()
                {
                    City       = input.AddressInput.City,
                    PostalCode = input.AddressInput.PostalCode,
                    State      = input.AddressInput.State,
                    Line1      = input.AddressInput.Line1,
                    Line2      = input.AddressInput.Line2,
                    Line3      = input.AddressInput.Line3,
                    Line4      = input.AddressInput.Line4
                }
            };

            context.Properties.Add(property);
            await context.SaveChangesAsync();

            return(new CreatePropertyPayload(property));
        }
        public async Task <AddImagePayload> AddImageAsync(
            AddImageInput input,
            [ScopedService] TenantFileContext context)
        {
            var(fileName, thumb, tenantId, residenceId, labels) = input;

            var image = new Image
            {
                Name          = fileName,
                Labels        = labels,
                ThumbnailName = thumb,
            };

            context.Images.Add(image);

            var phones
                = context.Phones.AsQueryable()
                  .Where(p => p.Tenants.Select(t => t.Id).Contains(tenantId)).ToList();

            phones.ForEach(p => p.Images.Add(image));



            await context.SaveChangesAsync();

            return(new AddImagePayload(image));
        }
示例#3
0
        public async Task <CreateResidencePayload> CreateResidence(CreateResidenceInput input,
                                                                   [ScopedService] TenantFileContext context, CancellationToken cancellationToken)

        {
            var residence = new Residence
            {
                PropertyId = input.PropertyId,

                Address = new Address()
                {
                    City       = input.AddressInput.City,
                    PostalCode = input.AddressInput.PostalCode,
                    State      = input.AddressInput.State,
                    Line1      = input.AddressInput.Line1,
                    Line2      = input.AddressInput.Line2,
                    Line3      = input.AddressInput.Line3,
                    Line4      = input.AddressInput.Line4
                }
            };

            context.Residences.Add(residence);
            await context.SaveChangesAsync(cancellationToken);

            return(new CreateResidencePayload(residence));
        }
示例#4
0
        public async Task <EditTenantPayload> EditTenantAsync(
            EditTenantInput inputTenant,
            [ScopedService] TenantFileContext context,
            CancellationToken cancellationToken)
        {
            // var (nameInput, phoneInput, residenceInput, residenceIdInput) = inputTenant;

            Tenant?tenant = await context.Tenants.FirstOrDefaultAsync(x => x.Id == inputTenant.TenantId);

            Phone phone = await context.Phones.FirstOrDefaultAsync(x => x.PhoneNumber == inputTenant.PhoneNumber) ?? new Phone()
            {
                PhoneNumber = inputTenant.PhoneNumber
            };

            // If it doesn't exist, create a new tenant number
            if (tenant == null)
            {
                tenant = new Tenant
                {
                    Name   = inputTenant.Name,
                    Phones = new List <Phone> {
                        phone
                    }
                };
            }
            else
            {
                tenant.Name = inputTenant.Name;
            }
            if (inputTenant.CurrentResidence != null)
            {
                var(line1, line2, line3, line4, city, state, postalCode) = inputTenant.CurrentResidence !.AddressInput;
                tenant.CurrentResidence = new Residence()
                {
                    Address = new Address()
                    {
                        Line1      = line1,
                        Line2      = line2,
                        Line3      = line3,
                        Line4      = line4,
                        City       = city,
                        State      = state,
                        PostalCode = postalCode
                    },
                    PropertyId = inputTenant.CurrentResidence.PropertyId
                };
            }
            else
            {
                tenant.ResidenceId = inputTenant.ResidenceId !;
            }

            await context.SaveChangesAsync(cancellationToken);

            return(new EditTenantPayload(tenant));
        }
        public async Task <IActionResult> CreateOrganizerAsync([FromQuery] string userUid)
        {
            //await using TenantFileContext dbContext = dbContextFactory.CreateDbContext();
            context.Organizers.Add(new Organizer()
            {
                Uid = userUid
            });

            await context.SaveChangesAsync();

            return(StatusCode(201));
        }
示例#6
0
        public async Task <CreateTenantPayload> CreateTenantAsync(
            CreateTenantInput inputTenant,
            [ScopedService] TenantFileContext context,
            CancellationToken cancellationToken)
        {
            var(nameInput, phoneInput, residenceInput, residenceIdInput) = inputTenant;
            // See if the phone number exists already
            Phone?phone = context.Phones.FirstOrDefault(x => x.PhoneNumber == inputTenant.PhoneNumber);

            // If it doesn't exist, create a new phone number
            if (phone == null)
            {
                phone = new Phone
                {
                    PhoneNumber = phoneInput
                };
            }
            var tenant = new Tenant
            {
                Name   = nameInput,
                Phones = new List <Phone> {
                    phone
                },
            };

            if (residenceInput != null)
            {
                var(line1, line2, line3, line4, city, state, postalCode) = residenceInput !.AddressInput;
                tenant.CurrentResidence = new Residence()
                {
                    Address = new Address()
                    {
                        Line1      = line1,
                        Line2      = line2,
                        Line3      = line3,
                        Line4      = line4,
                        City       = city,
                        State      = state,
                        PostalCode = postalCode
                    },
                    PropertyId = residenceInput.PropertyId
                };
            }
            else
            {
                tenant.ResidenceId = residenceIdInput !;
            }

            var tenantEntry = context.Tenants.Update(tenant);
            await context.SaveChangesAsync(cancellationToken);

            return(new CreateTenantPayload(tenant));
        }
示例#7
0
        private static void InitializeDatabase(IApplicationBuilder app)
        {
            using IServiceScope? serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>() !.CreateScope();

            var factory = serviceScope.ServiceProvider.GetRequiredService <IDbContextFactory <TenantFileContext> >();

            using TenantFileContext dbContext = factory.CreateDbContext();

            if (dbContext.Database.EnsureCreated())
            {
                dbContext.SaveChangesAsync();
            }
        }
示例#8
0
        public async Task <TwiMLResult> SmsWebhook(SmsRequest request, int numMedia)
        {
            DateTime timeStamp = DateTime.Now;
            var      filenames = await SaveMediaAsync(numMedia);

            //await using TenantFileContext dbContext = dbContextFactory.CreateDbContext();
            var phone = context.Phones.FirstOrDefault(x => x.PhoneNumber == request.From);

            bool newPhone = false;

            if (phone == null)
            {
                newPhone = true;
                phone    = new Phone
                {
                    PhoneNumber = request.From,
                    Images      = new List <Models.Entities.Image>()
                };
                context.Phones.Add(phone);
            }

            foreach (var(image, thumbnail, labels) in filenames)
            {
                if (phone.Images == null)
                {
                    phone.Images = new List <Models.Entities.Image>();
                }
                phone.Images.Add(new Models.Entities.Image
                {
                    Name          = image,
                    ThumbnailName = thumbnail,
                    Labels        = labels
                });
            }
            await context.SaveChangesAsync();

            if (newPhone == true)
            {
                await eventSender.SendAsync(nameof(PhoneSubscriptions.OnNewPhoneReceived), phone.Id);//ConfigureAwait?
            }
            var response    = new MessagingResponse();
            var messageBody = numMedia == 0 ? "No images were recieved from your message. Please send us an image of what you are trying to document." :
                              $"Thanks for sending us {numMedia} file(s)!";

            response.Message(messageBody);
            return(TwiML(response));
        }