예제 #1
0
        public async Task WipeClaimsAsync()
        {
            var images = new List <string>();

            using (var dbContext = new Mobile.ClaimsDbContext())
            {
                var claims = dbContext.Claims.ToArray();
                dbContext.Claims.RemoveRange(claims);
                await dbContext.SaveChangesAsync();
            }

            using (var dbContext = new CRM.ClaimsDbContext())
            {
                var claims = await dbContext.Claims
                             .Include(i => i.Images)
                             .ToArrayAsync();

                var otherParties = await dbContext.OtherParties
                                   .ToArrayAsync();

                foreach (var claim in claims)
                {
                    images.AddRange(claim.Images.Select(i => i.ImageUrl));
                }
                foreach (var otherParty in otherParties)
                {
                    images.Add(otherParty.LicensePlateImageUrl);
                    images.Add(otherParty.InsuranceCardImageUrl);
                    images.Add(otherParty.DriversLicenseImageUrl);
                }

                dbContext.Claims.RemoveRange(claims);
                dbContext.OtherParties.RemoveRange(otherParties);
                await dbContext.SaveChangesAsync();
            }

            var storageAccount = CloudStorageAccount.Parse(AppSettings.StorageConnectionString);
            var blobClient     = storageAccount.CreateCloudBlobClient();

            foreach (var image in images)
            {
                var blob = await blobClient.GetBlobReferenceFromServerAsync(new Uri(image));

                if (await blob.ExistsAsync())
                {
                    await blob.DeleteAsync();
                }
            }
        }
        private async Task SeedCRMClaimsDbAsync(string userId, string firstName, string lastName, string email, Vehicle[] vehicles)
        {
            using (var dbContext = new CRM.ClaimsDbContext())
            {
                var customer = mapper.Map <CRM.Customer>(CustomerData);
                customer.UserId    = userId;
                customer.FirstName = firstName;
                customer.LastName  = lastName;
                customer.Email     = email;

                foreach (var vehicle in vehicles)
                {
                    var customerVehicle = mapper.Map <CRM.CustomerVehicle>(vehicle.VehicleData);
                    customerVehicle.Customer = customer;
                    customerVehicle.ImageURL = vehicle.ImageUri.AbsoluteUri;
                    customer.Vehicles.Add(customerVehicle);
                    vehicle.CustomerVehicle = customerVehicle;
                }

                dbContext.Customers.Add(customer);
                await dbContext.SaveChangesAsync();
            }
        }
 public async Task <bool> IsCustomerExistedAsync(string userId)
 {
     using (var dbContext = new CRM.ClaimsDbContext())
         return(await dbContext.Customers.AnyAsync(i => i.UserId == userId));
 }