/// <summary>
        /// Gets list of Budgets models
        /// </summary>
        /// <returns>collection with Budget models</returns>
        public IEnumerable <Budget> GetBudgets(IncludeLevel includeLevel)
        {
            IEnumerable <Budget> budgets;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                budgets = Context.Budgets;
                break;

            case IncludeLevel.Level1:
                budgets = Context.Budgets
                          .Include(x => x.CreatedBy)
                          .Include(x => x.Owner)
                          .Include(x => x.LastModifiedBy);
                break;

            default:
                budgets = Context.Budgets
                          .Include(x => x.CreatedBy).ThenInclude(x => x.Manager)
                          .Include(x => x.Owner).ThenInclude(x => x.Manager)
                          .Include(x => x.LastModifiedBy);
                break;
            }

            return(budgets);
        }
Beispiel #2
0
        /// <summary>
        /// Gets collection of Invoice line models for given budget id
        /// </summary>
        /// <param name="budgetId">budget Id for which invoice liens should be retrieved</param>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>collection of invoices for given customer</returns>
        public IEnumerable <InvoiceLine> GetInvoiceLinesForBudget(string budgetId, IncludeLevel includeLevel)
        {
            IEnumerable <InvoiceLine> invoicesLines;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                invoicesLines = Context.InvoiceLines
                                .Where(x => x.BudgetId == budgetId);
                break;

            case IncludeLevel.Level1:
                invoicesLines = Context.InvoiceLines
                                .Include(x => x.CreatedBy)
                                .Include(x => x.LastModifiedBy)
                                .Include(x => x.Invoice)
                                .Include(x => x.Budget)
                                .Where(x => x.BudgetId == budgetId);
                break;

            default:
                invoicesLines = Context.InvoiceLines
                                .Include(x => x.CreatedBy)
                                .Include(x => x.LastModifiedBy)
                                .Include(x => x.Invoice).ThenInclude(x => x.CreatedBy)
                                .Include(x => x.Invoice).ThenInclude(x => x.Customer).ThenInclude(x => x.CreatedBy)
                                .Include(x => x.Budget).ThenInclude(x => x.CreatedBy)
                                .Where(x => x.BudgetId == budgetId);
                break;
            }

            return(invoicesLines);
        }
        /// <summary>
        /// Gets Budget for given Id or throws exceptions if budget not found.
        /// </summary>
        /// <param name="budgetId">Budget id</param>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>Budget based on budget for given Id</returns>
        public Budget GetBudgetById(string budgetId, IncludeLevel includeLevel)
        {
            Budget budget;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                budget = Context.Budgets
                         .FirstOrDefault(x => x.Id == budgetId);
                break;

            case IncludeLevel.Level1:
                budget = Context.Budgets
                         .Include(x => x.CreatedBy)
                         .Include(x => x.Owner)
                         .Include(x => x.LastModifiedBy)
                         .FirstOrDefault(x => x.Id == budgetId);
                break;

            default:
                budget = Context.Budgets
                         .Include(x => x.CreatedBy).ThenInclude(x => x.Manager)
                         .Include(x => x.Owner).ThenInclude(x => x.Manager)
                         .Include(x => x.LastModifiedBy)
                         .FirstOrDefault(x => x.Id == budgetId);
                break;
            }

            if (budget == null)
            {
                throw new ArgumentException("Brak budżetu o podanym Id", nameof(budget));
            }

            return(budget);
        }
Beispiel #4
0
        /// <summary>
        /// Gets list of Customers models
        /// </summary>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>collection with CustomerViewModels</returns>
        public IEnumerable <Customer> GetCustomers(IncludeLevel includeLevel)
        {
            IEnumerable <Customer> customers;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                customers = Context.Customers;
                break;

            case IncludeLevel.Level1:
                customers = Context.Customers
                            .Include(x => x.CreatedBy)
                            .Include(x => x.LastModifiedBy);
                break;

            default:
                customers = Context.Customers
                            .Include(x => x.CreatedBy).ThenInclude(x => x.Manager)
                            .Include(x => x.LastModifiedBy);
                break;
            }

            return(customers);
        }
Beispiel #5
0
        /// <summary>
        /// Gets collection of Invoice models
        /// </summary>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>collection with Invoice models</returns>
        public IEnumerable <Invoice> GetInvoices(IncludeLevel includeLevel)
        {
            IEnumerable <Invoice> invoices;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                invoices = Context.Invoices;
                break;

            case IncludeLevel.Level1:
                invoices = Context.Invoices
                           .Include(x => x.Customer)
                           .Include(x => x.Customer)
                           .Include(x => x.Budget)
                           .Include(x => x.Budget)
                           .Include(x => x.CreatedBy)
                           .Include(x => x.LastModifiedBy);
                break;

            default:
                invoices = Context.Invoices
                           .Include(x => x.Customer).ThenInclude(x => x.CreatedBy)
                           .Include(x => x.Customer).ThenInclude(x => x.LastModifiedBy)
                           .Include(x => x.Budget).ThenInclude(x => x.CreatedBy)
                           .Include(x => x.Budget).ThenInclude(x => x.LastModifiedBy)
                           .Include(x => x.CreatedBy)
                           .Include(x => x.LastModifiedBy);
                break;
            }

            return(invoices);
        }
Beispiel #6
0
        /// <summary>
        /// Gets Customer for given Id or throws exceptions if budget not found.
        /// </summary>
        /// <param name="id">Customer id</param>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>Customer based on customer for given Id</returns>
        public Customer GetCustomerById(string id, IncludeLevel includeLevel)
        {
            Customer customer;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                customer = Context.Customers
                           .FirstOrDefault(x => x.Id == id);
                break;

            case IncludeLevel.Level1:
                customer = Context.Customers
                           .Include(x => x.CreatedBy)
                           .Include(x => x.LastModifiedBy)
                           .FirstOrDefault(x => x.Id == id);
                break;

            default:
                customer = Context.Customers
                           .Include(x => x.CreatedBy).ThenInclude(x => x.Manager)
                           .Include(x => x.LastModifiedBy)
                           .FirstOrDefault(x => x.Id == id);
                break;
            }

            if (customer == null)
            {
                throw new ArgumentException("Bark klienta o podanym Id");
            }

            return(customer);
        }
Beispiel #7
0
        public IQueryable <ISubGroup> GetSubGroupQuery(IncludeLevel includeLevel)
        {
            if (includeLevel <= IncludeLevel.SubGroup)
            {
                return(this.Set <SubGroup>());
            }

            return(this.GetSubGroupAllQuery());
        }
Beispiel #8
0
        public async ValueTask <IGroup> GetGroupAsync(long id, IncludeLevel includeLevel)
        {
            var response = await this.client.GetGroupAsync(new GetGroupRequest()
            {
                Id = id, IncludeLevel = (int)includeLevel
            });

            return(response.Group);
        }
Beispiel #9
0
        public async ValueTask <IEnumerable <IGroup> > GetGroupsAsync(IncludeLevel includeLevel)
        {
            var response = await this.client.GetGroupsAsync(new GetGroupsRequest()
            {
                IncludeLevel = (int)includeLevel
            });

            return(response.Groups.ToList().AsReadOnly());
        }
Beispiel #10
0
        public async ValueTask <ICategory> GetCategoryAsync(long id, IncludeLevel includeLevel)
        {
            var response = await this.client.GetCategoryAsync(new GetCategoryRequest()
            {
                Id = id, IncludeLevel = (int)includeLevel
            });

            return(response.Category);
        }
Beispiel #11
0
 public async ValueTask <IEnumerable <ICategory> > GetCategoriesAsync(IncludeLevel includeLevel)
 {
     await using (var context = this.dataContextFactory.Create())
     {
         return((await context.GetCategoryQuery(includeLevel)
                 .ToListAsync()
                 .ConfigureAwait(false))
                .AsReadOnly());
     }
 }
Beispiel #12
0
        public async ValueTask<IGroup> GetGroupAsync(long id, IncludeLevel includeLevel)
        {
            if (id <= 0)
                throw new ArgumentOutOfRangeException(nameof(id), $"{nameof(id)} must be greater than 0");

            await using (var context = this.dataContextFactory.Create())
            {
                return await context
                    .GetGroupQuery(includeLevel)
                    .FirstOrDefaultAsync(x => x.Id == id)
                    .ConfigureAwait(false);
            }
        }
Beispiel #13
0
        public IQueryable <IGroup> GetGroupQuery(IncludeLevel includeLevel)
        {
            if (includeLevel <= IncludeLevel.Group)
            {
                return(this.Set <Group>());
            }

            if (includeLevel == IncludeLevel.SubGroup)
            {
                return(this.GetGroupIncludeSubGroupQuery());
            }

            return(this.GetGroupAllQuery());
        }
Beispiel #14
0
        public IQueryable <ICategory> GetCategoryQuery(IncludeLevel includeLevel)
        {
            if (includeLevel <= IncludeLevel.Category)
            {
                return(this.Set <Category>());
            }

            if (includeLevel == IncludeLevel.Group)
            {
                return(this.GetCategoryIncludeGroupQuery());
            }

            if (includeLevel == IncludeLevel.SubGroup)
            {
                return(this.GetCategoryIncludeSubGroupQuery());
            }

            return(this.GetCategoryAllQuery());
        }
Beispiel #15
0
        /// <summary>
        /// Gets Invoice line for given Id or throws exceptions if budget not found.
        /// </summary>
        /// <param name="lineId">Invoice line id</param>
        /// <param name="invoiceId">Invoice id</param>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>Budget based on budget for given Id</returns>
        public InvoiceLine GetInvoiceLineById(string lineId, string invoiceId, IncludeLevel includeLevel)
        {
            var invoice = GetInvoiceById(invoiceId, IncludeLevel.None);

            InvoiceLine invoiceLine;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                invoiceLine = Context.InvoiceLines
                              .SingleOrDefault(x => x.Id == lineId && x.InvoiceId == invoice.Id);
                break;

            case IncludeLevel.Level1:
                invoiceLine = Context.InvoiceLines
                              .Include(x => x.Invoice)
                              .Include(x => x.Budget)
                              .Include(x => x.CreatedBy)
                              .Include(x => x.LastModifiedBy)
                              .SingleOrDefault(x => x.Id == lineId && x.InvoiceId == invoice.Id);
                break;

            default:
                invoiceLine = Context.InvoiceLines
                              .Include(x => x.Invoice).ThenInclude(x => x.CreatedBy)
                              .Include(x => x.Invoice).ThenInclude(x => x.LastModifiedBy)
                              .Include(x => x.Invoice).ThenInclude(x => x.Budget)
                              .Include(x => x.Budget).ThenInclude(x => x.CreatedBy)
                              .Include(x => x.Budget).ThenInclude(x => x.LastModifiedBy)
                              .Include(x => x.CreatedBy)
                              .Include(x => x.LastModifiedBy)
                              .SingleOrDefault(x => x.Id == lineId && x.InvoiceId == invoice.Id);
                break;
            }

            if (invoiceLine == null)
            {
                throw new ArgumentException("Linia o podanym Id nie istnieje dla wskazanej faktury", nameof(invoice));
            }

            return(invoiceLine);
        }
Beispiel #16
0
        /// <summary>
        /// Gets Invoice for given Id or throws exceptions if budget not found.
        /// </summary>
        /// <param name="invoiceId">Invoice id</param>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>Budget based on budget for given Id</returns>
        public Invoice GetInvoiceById(string invoiceId, IncludeLevel includeLevel)
        {
            Invoice invoice;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                invoice = Context.Invoices
                          .SingleOrDefault(x => x.Id == invoiceId);
                break;

            case IncludeLevel.Level1:
                invoice = Context.Invoices
                          .Include(x => x.Customer)
                          .Include(x => x.Budget)
                          .Include(x => x.CreatedBy)
                          .Include(x => x.LastModifiedBy)
                          .SingleOrDefault(x => x.Id == invoiceId);
                break;

            default:
                invoice = Context.Invoices
                          .Include(x => x.Customer).ThenInclude(x => x.CreatedBy)
                          .Include(x => x.Customer).ThenInclude(x => x.LastModifiedBy)
                          .Include(x => x.Budget).ThenInclude(x => x.CreatedBy)
                          .Include(x => x.Budget).ThenInclude(x => x.LastModifiedBy)
                          .Include(x => x.CreatedBy)
                          .Include(x => x.LastModifiedBy)
                          .SingleOrDefault(x => x.Id == invoiceId);
                break;
            }

            if (invoice == null)
            {
                throw new ArgumentException("Brak faktury o podanym Id", nameof(invoice));
            }

            return(invoice);
        }
Beispiel #17
0
        /// <summary>
        /// Gets collection of Invoice line models for given invoice Id
        /// </summary>
        /// <param name="invoiceId">Invoice id</param>
        /// <param name="includeLevel">indicates level of dependencies to be retrieved from database</param>
        /// <returns>collection with Invoice models</returns>
        public IEnumerable <InvoiceLine> GetInvoiceLines(string invoiceId, IncludeLevel includeLevel)
        {
            var invoice = GetInvoiceById(invoiceId, IncludeLevel.None);

            IEnumerable <InvoiceLine> invoiceLines;

            switch (includeLevel)
            {
            case IncludeLevel.None:
                invoiceLines = Context.InvoiceLines
                               .Where(x => x.InvoiceId == invoice.Id);
                break;

            case IncludeLevel.Level1:
                invoiceLines = Context.InvoiceLines
                               .Include(x => x.Invoice)
                               .Include(x => x.Budget)
                               .Include(x => x.CreatedBy)
                               .Include(x => x.LastModifiedBy)
                               .Where(x => x.InvoiceId == invoice.Id);
                break;

            default:
                invoiceLines = Context.InvoiceLines
                               .Include(x => x.Invoice).ThenInclude(x => x.CreatedBy)
                               .Include(x => x.Invoice).ThenInclude(x => x.LastModifiedBy)
                               .Include(x => x.Budget).ThenInclude(x => x.CreatedBy)
                               .Include(x => x.Budget).ThenInclude(x => x.LastModifiedBy)
                               .Include(x => x.Budget).ThenInclude(x => x.Owner)
                               .Include(x => x.CreatedBy)
                               .Include(x => x.LastModifiedBy)
                               .Where(x => x.InvoiceId == invoice.Id);
                break;
            }

            return(invoiceLines);
        }
Beispiel #18
0
 public ValueTask <IEnumerable <ICategory> > GetCategoriesAsync(IncludeLevel includeLevel) =>
 this.categoryRepository.GetCategoriesAsync(includeLevel);
Beispiel #19
0
 public ValueTask <IGroup> GetGroupAsync(long id, IncludeLevel includeLevel) =>
 this.groupRepository.GetGroupAsync(id, includeLevel);
Beispiel #20
0
 public ValueTask <IEnumerable <IGroup> > GetGroupsAsync(IncludeLevel includeLevel) =>
 this.groupRepository.GetGroupsAsync(includeLevel);
Beispiel #21
0
 public ValueTask <ICategory> GetCategoryAsync(long id, IncludeLevel includeLevel) =>
 this.categoryRepository.GetCategoryAsync(id, includeLevel);