protected override void DoSeed() { var parser = new ExcelFileParser <CategoryFileRecordModel>(); ParseResult <CategoryFileRecordModel> result = null; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName)) { result = parser.Parse(stream); } Defensive.AssertTrue(result.Success); foreach (var group in result.Records.GroupBy(x => x.Category)) { var category = new Category { Name = group.Key }; group.ToList().ForEach(x => category.Categories.Add(new SubCategory { Name = x.SubCategory })); Context.Add(category); //todo use repository } }
protected override void DoSeed() { var parser = new ExcelFileParser <EntityAccountFileRecordModel>(); ParseResult <EntityAccountFileRecordModel> result = null; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName)) { result = parser.Parse(stream); } Defensive.AssertTrue(result.Success); foreach (var group in result.Records.GroupBy(x => x.Name)) { var entity = Mapper.Map <Entity>(group.First()); entity.Ibans = group.Select(x => { if (x.Iban != null) { x.Iban = x.Iban.Replace(" ", ""); } return(Mapper.Map <Iban>(x)); }) .ToList(); Context.Add(entity); //todo use repository } }
public ListRequest ToListRequest(int page) { Defensive.AssertTrue(page > 0, "Page can't be less than 1"); var skip = (page - 1) * ItemsPerPage; return(new ListRequest(Filters, Orders, skip, ItemsPerPage)); }
private void ProcessRecords(long logId, List <TransactionFileRecordModel> records, string fileName, long entityId) { if (entityId == 0 && records.Count(x => string.IsNullOrEmpty(x.PayerAccount)) > records.Count / 2) { LogError(logId, $"File '{fileName}' has no 'Payer Account' column specified, please select necessary 'Payer Account' in the dropdown."); return; } foreach (var record in records) { try { var domain = Mapper.Map <TransactionDomain>(record); if (!string.IsNullOrEmpty(record.PayerAccount)) { domain.Entity = EntityRepository.FindEntityByIban(record.PayerAccount); Defensive.AssertNotNull(domain.Entity, $"Entity with IBAN '{record.PayerAccount}' was not found"); } else { Defensive.AssertTrue(entityId > 0, "Entity is not specified"); domain.Entity = new ValueObject { Id = entityId }; } domain.RecipientEntity = EntityRepository.FindEntityByIban(record.ToAccount); if (record.Note?.Trim() != null) { var prefix = Regex.Match(record.Note?.Trim(), @"^([A-Za-z0-9]*)[^, -_]*")?.Value?.ToLower(); //text before first space , - _ domain.Project = ProjectRepository.FindProjectByPrefixInNote(prefix); } var res = Repository.TryImportTransaction(domain); if (res == TransactionImportResult.Success) { Log.Logger().Information("Transaction id '{id}' imported successfully", domain.IdOfTransaction); } else { Log.Logger().Warning("Transaction id '{id}' import failed with reason {reason}", domain.IdOfTransaction, res.ToString()); } } catch (Exception e) { LogError(logId, $"Failed to import record with id : {record.RowId}, File '{fileName}'", e); } } }
public UploadFileLogDetails GetLogsById(long id) { Defensive.AssertTrue(id > 0); return(Context.FileUploadLogs .Include(x => x.Errors) .FindOptional(x => x.Id == id) .SomeOrEntityNotFoundException() .Do(e => Context.Entry(e).GetDatabaseValues()) .Map(Mapper.Map <UploadFileLogDetails>) .ValueOrFailure()); }
private async Task PopulateRoles() { var result = await RoleManager.CreateAsync(new IdentityRole(RoleNames.Admin)); Defensive.AssertTrue(result.Succeeded, string.Join("; ", result.Errors)); result = await RoleManager.CreateAsync(new IdentityRole(RoleNames.BackOffice)); Defensive.AssertTrue(result.Succeeded, string.Join("; ", result.Errors)); result = await RoleManager.CreateAsync(new IdentityRole(RoleNames.Customer)); Defensive.AssertTrue(result.Succeeded, string.Join("; ", result.Errors)); }
private async Task PopulateSystemUser() { var user = new ApplicationUser { UserName = Constants.DefaultUser, Email = Constants.DefaultUser }; var result = await UserManager.CreateAsync(user, Constants.DefaultUserPassword); Defensive.AssertTrue(result.Succeeded, string.Join("; ", result.Errors)); var roleResult = await UserManager.AddToRoleAsync(user, RoleNames.Admin); Defensive.AssertTrue(roleResult.Succeeded, string.Join("; ", roleResult.Errors)); }
private ManyToManyRelationVm GetItems() { var leftEntityId = GetFromSession <long>(SessionKeys.ChildPageManyToManyLeftEntityFk); Defensive.AssertTrue(leftEntityId > 0, "Session is expired"); if (GetFromSession(SessionKeys.ChildPageManyToManyIsReadonlyFlag, false)) { ViewData.GetPageContext().SetTableIsReadonly(); } ViewData[MvcViewConstants.Title] = Title; return(new ManyToManyRelationVm(leftEntityId, Service.GetRightItems(leftEntityId))); }
protected MvcTableResponse <TDto, TKey> GetTableItemsPerPage(int?page) { if (!page.HasValue) { page = GetFromSession(SessionKeys.CurrentPage, 1); } Defensive.AssertTrue(page >= 1); SaveToSession(SessionKeys.CurrentPage, page); var request = GetTableRequest(); var listResult = request.FromListResult <TDto, TKey>(Service.List(request.ToListRequest(page.Value)), page.Value); return(listResult.ToMvcTableResponse()); }
public FormDescriptor Build() { Defensive.AssertTrue(Descriptor.Items.Count > 0, "Form has no items specified"); return(Descriptor); }