public async Task MapPointsToCategoriesAsync() { var file = File.ReadAllLines(_options.Value.PointsToCatMapPath); var pointsWithCategories = file .Select( x => x.Split("_", StringSplitOptions.RemoveEmptyEntries).Select(y => y.Trim()).ToArray() ) .Where(x => { if (!x.IsNullOrEmpty() && x.Count() > 1) { return(true); } Console.WriteLine("Bad Line: " + string.Join(" _ ", x)); return(false); }) .Select( x => (PointName: x[0], Categories: x[1] .Split(",", StringSplitOptions.RemoveEmptyEntries) .Select(y => y.Trim()).Distinct().ToArray()) ).ToArray(); foreach (var pointWithCategories in pointsWithCategories) { var points = await _dbContext.WasteTakePoints .Where(p => p.Name == pointWithCategories.PointName).ToListAsync().ConfigureAwait(false); var categories = await _dbContext.WasteCategories.Where(c => pointWithCategories.Categories.Contains(c .Name)).ToListAsync().ConfigureAwait(false); if (!points.IsNullOrEmpty() && categories.Any()) { points.Select(point => point.LinksToCategories = categories.Select(c => new WasteTakePointToCategoryLinkDbo() { Id = Guid.NewGuid(), CategoryId = c.Id, WasteTakePointId = point.Id }).ToList()).ToList(); } else { Console.WriteLine( $"Bad Line: {pointWithCategories.PointName} _ {string.Join(',', pointWithCategories.Categories)}"); } } await _dbContext.SaveChangesAsync().ConfigureAwait(false); }
public async Task <UserViewModel> CreateUserAsync(UserViewModel createModel) { var user = mapper.Map <GarbageAppUser>(createModel); if (!(await CheckIsPossibleCreateUserAsync(user).ConfigureAwait(false))) { return(null); } user.AddServices(categoriesService, wasteTakePointService); await user.UpdateTrashCansByCurrentLocationAsync().ConfigureAwait(false); var dbUser = mapper.Map <GarbageAppUserDbo>(user); await dbContext.AppUsers.AddAsync(dbUser).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); return(mapper.Map <UserViewModel>(user)); }