Пример #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 SeedMobileClaimsDbAsync(string userId, Vehicle[] vehicles)
 {
     using (var dbContext = new Mobile.ClaimsDbContext())
     {
         foreach (var item in vehicles)
         {
             var vehicle = mapper.Map <Mobile.Vehicle>(item.VehicleData);
             vehicle.Id        = item.Id.ToString();
             vehicle.UserId    = userId;
             vehicle.VehicleId = item.CustomerVehicle.Id;
             vehicle.Deleted   = false;
             dbContext.Vehicles.Add(vehicle);
         }
         await dbContext.SaveChangesAsync();
     }
 }