Exemple #1
0
        public async Task <DocumentView> GetDocumentFromCollection(Guid documentId)
        {
            var documentQuery      = _ctx.documentview.Where(k => k.DocumentId == documentId);
            var documentCollection = await ODataBasics.GetDSCollection(documentQuery);

            return(documentCollection.FirstOrDefault());
        }
Exemple #2
0
        public async Task <DocumentFolderView> GetFolderFromCollection(Guid folderId)
        {
            var folderQuery      = _ctx.documentfolderview.Where(k => k.DocumentFolderId == folderId);
            var folderCollection = await ODataBasics.GetDSCollection(folderQuery);

            return(folderCollection.FirstOrDefault());
        }
Exemple #3
0
        public async Task <DocumentRelationExtend> CreateNewDocumentRelation(BudgetPositionExtend actualExpenseBudgetPosition, DocumentView document)
        {
            // create new query
            var query    = ODataBasics.GetDSCollection <DocumentRelationExtend>(_context);
            var relation = new DocumentRelationExtend();

            query.Add(relation);

            // set values
            relation.DocumentId = document.DocumentId;
            relation.ProjectId  = document.ProjectId;
            relation.ObjectId   = actualExpenseBudgetPosition.BudgetPositionId;

            // save
            await _context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties);

            return(relation);
        }
Exemple #4
0
        public async Task <DocumentView> CreateNewInvoiceDocumentLink(Uri path, Guid projectId)
        {
            // create new query
            var query    = ODataBasics.GetDSCollection <DocumentView>(_context);
            var document = new DocumentView();

            query.Add(document);

            // set values
            document.FileName       = path.ToString();
            document.IsFileLink     = false;
            document.IsInternetLink = true;
            document.ProjectId      = projectId;

            // save
            await _context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties);

            return(document);
        }
Exemple #5
0
        public Task <DataServiceCollection <DocumentSync> > GetChangesSince(DateTimeOffset sinceDate,
                                                                            DocumentSyncChangeType changeType = DocumentSyncChangeType.All)
        {
            var query = _ctx.documentsync
                        .OrderByDescending(k => k.UpdatedAt)
                        .Where(k => k.UpdatedAt > sinceDate);

            switch (changeType)
            {
            case DocumentSyncChangeType.File:
                query = query.Where(k => !k.IsFolder);
                break;

            case DocumentSyncChangeType.Folders:
                query = query.Where(k => k.IsFolder);
                break;
            }

            return(ODataBasics.GetDSCollection(query));
        }
Exemple #6
0
        private async Task <BudgetExtend> CreateActualExpense(BudgetExtend plannedExpense)
        {
            if (plannedExpense == null)
            {
                return(null);
            }

            // create new query
            var query  = ODataBasics.GetDSCollection <BudgetExtend>(_context);
            var budget = new BudgetExtend();

            query.Add(budget);

            // set values
            budget.Name       = plannedExpense.Name;
            budget.BudgetType = ConstantsHelper.BUDGET_TYPE_ACTUAL_EXPENSE;
            budget.ProjectId  = plannedExpense.ProjectId;

            // save
            await _context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties);

            return(budget);
        }
Exemple #7
0
        private async Task <BudgetPositionExtend> CreateNewBudgetPosition(BudgetExtend actualExpenseBudget,
                                                                          BudgetPositionExtend plannedExpenseBudgetPosition, double amount, string invoiceNumber)
        {
            // create new query
            var query = ODataBasics.GetDSCollection <BudgetPositionExtend>(_context);
            var actualExpenseBudgetPosition = new BudgetPositionExtend();

            query.Add(actualExpenseBudgetPosition);

            // set values
            actualExpenseBudgetPosition.BudgetId         = actualExpenseBudget.BudgetId;
            actualExpenseBudgetPosition.ShortDescription = plannedExpenseBudgetPosition.ShortDescription;
            actualExpenseBudgetPosition.GroupId          = plannedExpenseBudgetPosition.GroupId;
            actualExpenseBudgetPosition.PricePerUnit     = amount;
            actualExpenseBudgetPosition.Quantity         = 1;
            actualExpenseBudgetPosition.Unit             = string.Format(SEE_INVOICE_HINT, invoiceNumber);
            actualExpenseBudgetPosition.IsBilled         = true;

            // save
            await _context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties);

            return(actualExpenseBudgetPosition);
        }
        public async Task AddOrUpdateByName(IDictionary <string, string> dict)
        {
            if (!dict.ContainsKey("Name"))
            {
                throw new ArgumentException(nameof(dict) + " should contain 'Name'");
            }

            var name           = dict["Name"];
            var ctx            = _client.GetContext();
            var query          = GetEntityQuery(ctx, name);
            var dataCollection = await ODataBasics.GetDSCollection(query);

            var entity = dataCollection.FirstOrDefault();

            if (entity == null)
            {
                entity = new T();
                dataCollection.Add(entity);
            }

            await Update(ctx, entity, dict);

            await ctx.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties);
        }
Exemple #9
0
 public static Task <DataServiceCollection <T> > ToDataServiceCollection <T>(this IQueryable <T> query)
 {
     return(ODataBasics.GetDSCollection(query));
 }