private TableViewModel GetModel(IHtmlHelper helper) { var model = helper.ViewData.Model as TableViewModel; Defensive.AssertNotNull(model); return(model); }
public static MvcPageContext GetPageContext(this IHtmlHelper html) { var context = html.ViewContext.ViewData[MvcPageContext.Name] as MvcPageContext; Defensive.AssertNotNull(context, "GetPageContext can't be null"); return(context); }
public static IQueryable <TDomain> ApplyTableRequestIQueryable <TEntity, TDomain, TKey>(this IQueryable <TEntity> query, ListRequest request, params SortOrder[] sortOrders) where TEntity : IEntity <TKey> where TDomain : IDomainBase <TKey> { var domainQuery = query.ProjectTo <TDomain>(); Defensive.AssertNotNull(domainQuery); if (request.Filters.Any()) { domainQuery = domainQuery.Where(FilterExpressionCreator.CreateFilterExpression <TEntity, TDomain>(request.Filters)); } domainQuery = Sort <TDomain, TKey>(domainQuery, sortOrders, request.Sorts); if (!request.SkipPaging) { domainQuery = domainQuery.Skip(request.Skip); if (request.Take > 0) { domainQuery = domainQuery.Take(request.Take); } } return(domainQuery); }
public static TableDescriptor GetTableDescriptor(this IHtmlHelper html) { var descriptor = html.ViewContext.ViewData[TableDescriptor.DescriptorName] as TableDescriptor; Defensive.AssertNotNull(descriptor, "GetTableDescriptor can't be null"); return(descriptor); }
public static FormItemsDescriptor GetFormItemDescriptor(this IHtmlHelper html) { var descriptor = html.ViewContext.ViewData[FormItemsDescriptor.DescriptorName] as FormItemsDescriptor; Defensive.AssertNotNull(descriptor, "Forms Item Descriptor is not found"); return(descriptor); }
public IHtmlContent Render(object model) { if (model == null) { return(new HtmlString("")); } var files = model as List <ValueObject>; Defensive.AssertNotNull(files); var stb = new StringBuilder(); foreach (var file in files) { var name = Path.GetFileNameWithoutExtension(file.Name); //var ext = Path.GetExtension(file.Name); if (name.Length > MaxNameLength) { name = $"{name.Substring(0, MaxNameLength)}..."; } stb.Append($"<div data-file-id='{file.Id}' class='custom-popover preview'>{name}</div>"); } return(new HtmlString(stb.ToString())); }
public T GetService <T>() { var service = _container != null?_container.GetService <T>() : throw new Exception("Test Fixture must be initialized"); Defensive.AssertNotNull(service, $"Service {typeof(T).FullName} is not registered in IoC container"); return(service); }
public static FileUploadLogError Create(string message) { Defensive.AssertNotNull(message, "Error message must not be null"); return(new FileUploadLogError { Message = message }); }
public void AddError(long logId, string message) { var log = Context.FileUploadLogs.SingleOrDefault(x => x.Id == logId); Defensive.AssertNotNull(log, $"Log with id({logId}) was not found"); log.Errors.Add(FileUploadLogError.Create(message)); Context.SaveChanges(); }
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 static string NormalizeIban(this string iban) { Defensive.AssertNotNull(iban, "Iban can not be null"); if (iban.Length > 10) { iban = iban.Substring(Math.Max(0, iban.Length - 10)); //get last 10 characters } return(iban); }
public void EndLog(long logId) { var log = Context.FileUploadLogs.SingleOrDefault(x => x.Id == logId); Defensive.AssertNotNull(log, $"Log with id({logId}) was not found"); log.Status = !log.Errors.Any() ? FileUploadStatus.FinishedSuccessfully : FileUploadStatus.FinishedWithErrors; log.EndDateTime = DateTimeContext.Now; Context.SaveChanges(); }
public long CreateLog(string fileName) { Defensive.AssertNotNull(fileName, "File name can't be empty"); var log = FileUploadLog.CreateFor(fileName); Context.Add(log); Context.SaveChanges(); return(log.Id); }
public static PropertyInfo GetPropertyInfoFromMemberExpression <TTarget, TValue>(this Expression <Func <TTarget, TValue> > expression) { var memberExpression = expression.Body as MemberExpression; Defensive.AssertNotNull(memberExpression); var propertyInfo = memberExpression.Member as PropertyInfo; Defensive.AssertNotNull(propertyInfo); return(propertyInfo); }
public static SortOrder CreateOrder <TSource>(Expression <Func <TSource, object> > propertyLambda, OrderDirection direction) { var expression = propertyLambda.Body as MemberExpression; Defensive.AssertNotNull(expression); var propInfo = expression.Member as PropertyInfo; Defensive.AssertNotNull(propInfo); return(new SortOrder(propInfo.Name, direction)); }
public IHtmlContent Render(object model) { if (model == null) { return(new HtmlString("")); } var value = model as ValueObject; Defensive.AssertNotNull(value); return(new HtmlString(value.Name)); }
public static Task <IHtmlContent> RenderEditButtonAsync <TModel>(this IHtmlHelper <TModel> htmlHelper) { var pageContext = htmlHelper.GetPageContext(); if (pageContext.TableCanEdit) { var model = htmlHelper.ViewData.Model as DomainBase; Defensive.AssertNotNull(model); var viewModel = new CrudButtonViewModel(CrudButtonsSettings.EditLabel, CrudButtonsSettings.EditUrl, CrudButtonsSettings.EditStyle, new { id = model.Id }); return(htmlHelper.PartialAsync("_CrudButton", viewModel)); } return(Task.FromResult <IHtmlContent>(null)); }
protected void SetMusterEntityId(TCreate model) { if (!IsChildPage) { return; } var childEntity = model as IChildEntity <TKey>; Defensive.AssertNotNull(childEntity, "Child entity must implement IChildEntity interface"); var fk = GetChildPageMusterFilter().Filters.Single(x => x.Type == FilterType.Number)?.Value; Defensive.AssertNotNull(fk, "Session for child page is expired"); childEntity.MusterEntityFk = (TKey)GetChildPageMusterFilter().Filters.Single(x => x.Type == FilterType.Number).Value; }
public static ListResult <TDomain> ApplyTableRequest <TEntity, TDomain, TKey>(this IQueryable <TEntity> query, ListRequest request, params SortOrder[] sortOrders) where TEntity : IEntity <TKey> where TDomain : IDomainBase <TKey> { var totalCount = query.Count(); var filtered = totalCount; var domainQuery = query.ProjectTo <TDomain>(); Defensive.AssertNotNull(domainQuery); if (request.Filters.Any()) { domainQuery = domainQuery.Where(FilterExpressionCreator.CreateFilterExpression <TEntity, TDomain>(request.Filters)); filtered = domainQuery.Count(); } domainQuery = Sort <TDomain, TKey>(domainQuery, sortOrders, request.Sorts); if (!request.SkipPaging) { domainQuery = domainQuery.Skip(request.Skip); if (request.Take > 0) { domainQuery = domainQuery.Take(request.Take); } } List <TDomain> list = domainQuery.ToList(); var config = Mapper.Configuration.FindTypeMapFor <TEntity, TDomain>(); var hasAfterMap = config != null && config.AfterMapActions.Any(); if (hasAfterMap) { //second pass TDomain => TDomain to apply AfterMap list = list.Select(x => Mapper.Map <TDomain>(x)).ToList(); } return(new ListResult <TDomain>(list, filtered, totalCount)); }
private void SetPageContext(ActionExecutingContext context) { var controller = context.Controller as Controller; Defensive.AssertNotNull(controller); var pageContext = GetPageContext(context); pageContext.ControllerName = controller.GetType().Name; if (context.HttpContext.Session.Get(GetSessionKey(SessionKeys.TableIsReadonly, controller), false)) { pageContext.SetTableIsReadonly(); } if (controller is ParentChildPageController contextAware) { pageContext.IsChildPage = contextAware.IsChildPage; } }
public async Task <IHtmlContent> RenderFilterAsync(IHtmlHelper helper) { Defensive.AssertNotNull(ColumnFilterRenderer, "ColumnFilterRenderer is null"); return(await ColumnFilterRenderer.RenderFilter(helper, this)); }
public Task <IHtmlContent> RenderAsync(IHtmlHelper htmlHelper) { Defensive.AssertNotNull(Renderer); return(Renderer.RenderAsync(htmlHelper, this)); }