private TableViewModel GetModel(IHtmlHelper helper)
        {
            var model = helper.ViewData.Model as TableViewModel;

            Defensive.AssertNotNull(model);
            return(model);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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()));
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public static FileUploadLogError Create(string message)
        {
            Defensive.AssertNotNull(message, "Error message must not be null");

            return(new FileUploadLogError
            {
                Message = message
            });
        }
Esempio n. 9
0
        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);
                }
            }
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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();
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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));
        }
Esempio n. 16
0
        public IHtmlContent Render(object model)
        {
            if (model == null)
            {
                return(new HtmlString(""));
            }

            var value = model as ValueObject;

            Defensive.AssertNotNull(value);

            return(new HtmlString(value.Name));
        }
Esempio n. 17
0
        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));
        }
Esempio n. 18
0
        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;
        }
Esempio n. 19
0
        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));
        }
Esempio n. 20
0
        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;
            }
        }
Esempio n. 21
0
        public async Task <IHtmlContent> RenderFilterAsync(IHtmlHelper helper)
        {
            Defensive.AssertNotNull(ColumnFilterRenderer, "ColumnFilterRenderer is null");

            return(await ColumnFilterRenderer.RenderFilter(helper, this));
        }
Esempio n. 22
0
        public Task <IHtmlContent> RenderAsync(IHtmlHelper htmlHelper)
        {
            Defensive.AssertNotNull(Renderer);

            return(Renderer.RenderAsync(htmlHelper, this));
        }