Exemple #1
0
        public async Task DeleteReturn(int id)
        {
            var productsInReturn = await Uow.ProductsReturned.AllAsyncByReturnId(id);

            foreach (var productInReturn in productsInReturn)
            {
                Uow.ProductsReturned.Remove(productInReturn.Id);
            }
            Uow.Returns.Remove(id);
            await Uow.SaveChangesAsync();
        }
Exemple #2
0
        public async Task ExecuteAsync(int protectionDocId, List <ICGSProtectionDoc> icgsProtectionDocs)
        {
            var protectionDocRepository = Uow.GetRepository <Domain.Entities.ProtectionDoc.ProtectionDoc>();
            var protectionDoc           = await protectionDocRepository.GetByIdAsync(protectionDocId);

            foreach (var icgsProtectionDoc in icgsProtectionDocs)
            {
                protectionDoc.IcgsProtectionDocs.Remove(icgsProtectionDoc);
            }
            await Uow.SaveChangesAsync();
        }
        public async Task ExecuteAsync(int protectionDocId, List <ProtectionDocEarlyReg> earlyRegs)
        {
            var protectionDocRepository = Uow.GetRepository <Domain.Entities.ProtectionDoc.ProtectionDoc>();
            var protectionDoc           = await protectionDocRepository.GetByIdAsync(protectionDocId);

            foreach (var earlyReg in earlyRegs)
            {
                protectionDoc.EarlyRegs.Add(earlyReg);
            }
            await Uow.SaveChangesAsync();
        }
Exemple #4
0
        public async Task ExecuteAsync(int protectionDocId, List <ProtectionDocConventionInfo> infos)
        {
            var protectionDocRepository = Uow.GetRepository <Domain.Entities.ProtectionDoc.ProtectionDoc>();
            var protectionDoc           = await protectionDocRepository.GetByIdAsync(protectionDocId);

            foreach (var info in infos)
            {
                protectionDoc.ProtectionDocConventionInfos.Remove(info);
            }
            await Uow.SaveChangesAsync();
        }
Exemple #5
0
        public async Task DeleteOrderWithProducts(int id)
        {
            var productInOrders = await Uow.ProductsInOrder.AllAsyncByOrderId(id);

            foreach (var productInOrder in productInOrders)
            {
                Uow.ProductsInOrder.Remove(productInOrder.Id);
            }
            Uow.Orders.Remove(id);
            await Uow.SaveChangesAsync();
        }
Exemple #6
0
        /*public override async Task<IEnumerable<ProductSold>> AllAsync()
         * {
         *  return await UOW.ProductsSold.AllAsync();
         * }
         *
         * public override async Task<ProductSold> FindAsync(params object[] id)
         * {
         *  return await UOW.ProductsSold.FindAsync(id);
         * }
         *
         * public async Task<IEnumerable<ProductSold>> AllAsyncByShop(int? shopId)
         * {
         *  return await UOW.ProductsSold.AllAsyncByShop(shopId);
         * }
         *
         * public async Task<IEnumerable<ProductSoldDTO>> AllAsyncByShopDTO(int? shopId)
         * {
         *  return await UOW.ProductsSold.AllAsyncByShopDTO(shopId);
         * }
         *
         * public async Task<ProductSoldDTO> GetAsyncByShopAndIdDTO(int id, int? shopId)
         * {
         *  return await UOW.ProductsSold.GetAsyncByShopAndIdDTO(id, shopId);
         * }
         *
         * public async Task<int> GetQuantity(int id)
         * {
         *  return await UOW.ProductsSold.GetQuantity(id);
         * }*/

        public async Task DeleteWithRestoration(int id)
        {
            var productSold = await Uow.ProductsSold.FindAsync(id);

            var product = await Uow.Products.FindProductInfoAsync(productSold.ProductId);

            product.Quantity = product.Quantity + productSold.Quantity;
            Uow.Products.Update(product);

            Uow.ProductsSold.Remove(id);
            await Uow.SaveChangesAsync();
        }
        public async Task <bool> DeleteChangeAsync(int changeId)
        {
            var result = await Uow.Changes.RemoveSoft(changeId);

            if (result == false)
            {
                return(false);
            }
            await Uow.SaveChangesAsync();

            return(true);
        }
        public async Task ExecuteAsync(int documentId)
        {
            var repository = Uow.GetRepository <Document>();

            var document = await repository.AsQueryable().FirstOrDefaultAsync(r => r.Id == documentId);

            if (document != null)
            {
                document.IsFinished = true;
                await Uow.SaveChangesAsync();
            }
        }
        public async Task ExecuteAsync(ProtectionDocBulletinRelation relation)
        {
            var repo        = Uow.GetRepository <ProtectionDocBulletinRelation>();
            var oldRelation = await repo.GetByIdAsync(relation.Id);

            oldRelation.BulletinId      = relation.BulletinId;
            oldRelation.ProtectionDocId = relation.ProtectionDocId;
            oldRelation.IsPublish       = relation.IsPublish;
            repo.Update(oldRelation);

            await Uow.SaveChangesAsync();
        }
        public async Task ExecuteAsync(int requestId, List <RequestEarlyReg> earlyRegs)
        {
            var requestRepository = Uow.GetRepository <Domain.Entities.Request.Request>();
            var request           = await requestRepository.GetByIdAsync(requestId);

            foreach (var earlyReg in earlyRegs)
            {
                earlyReg.RequestId = requestId;
                request.EarlyRegs.Add(earlyReg);
            }
            await Uow.SaveChangesAsync();
        }
Exemple #11
0
        public async Task ExecuteAsync(int documentId, UserInputDto userInputDto)
        {
            var repo  = Uow.GetRepository <Domain.Entities.Document.DocumentUserInput>();
            var input = new Domain.Entities.Document.DocumentUserInput
            {
                DocumentId = documentId,
                UserInput  = JsonConvert.SerializeObject(userInputDto)
            };
            await repo.CreateAsync(input);

            await Uow.SaveChangesAsync();
        }
        public async Task <int> ExecuteAsync(LogRecord log)
        {
            var logRecordRepo = Uow.GetRepository <LogRecord>();

            log.UserId = NiisAmbientContext.Current.User.Identity.UserId;

            await logRecordRepo.CreateAsync(log);

            await Uow.SaveChangesAsync();

            return(log.Id);
        }
Exemple #13
0
        public async Task <bool> RemoveRow(int rowId, int userId)
        {
            var deleted = await Uow.ReceiptRows.RemoveRowAsync(rowId, userId);

            if (deleted == false)
            {
                return(false);
            }
            await Uow.SaveChangesAsync();

            return(true);
        }
Exemple #14
0
        public async Task DeleteWithoutRestoration(int saleId)
        {
            var productsInSale = await Uow.ProductsSold.FindBySaleId(saleId);

            foreach (var productInSale in productsInSale)
            {
                Uow.ProductsSold.Remove(productInSale.Id);
            }

            Uow.Sales.Remove(saleId);
            await Uow.SaveChangesAsync();
        }
        public async Task <bool> DeleteProductAsync(int productId)
        {
            var result = await Uow.Products.RemoveSoft(productId);

            if (result == false)
            {
                return(false);
            }
            await Uow.SaveChangesAsync();

            return(true);
        }
Exemple #16
0
        public async Task Execute(int bulletinSectionId, EditBulletinSectionRequestDto requestDto)
        {
            var bulletinSectionRepository = Uow.GetRepository <BulletinSection>();
            var bulletinSection           = bulletinSectionRepository.GetById(bulletinSectionId);

            bulletinSection.Name       = requestDto.Name;
            bulletinSection.DateUpdate = DateTimeOffset.Now;

            bulletinSectionRepository.Update(bulletinSection);

            await Uow.SaveChangesAsync();
        }
Exemple #17
0
        public async Task <int> ExecuteAsync(DocumentWorkflow workflow, bool isPrevious = false)
        {
            var documentRepo   = Uow.GetRepository <Document>();
            var documentWfRepo = Uow.GetRepository <DocumentWorkflow>();
            var routeStageRepo = Uow.GetRepository <DicRouteStage>();
            var document       = await documentRepo.GetByIdAsync(workflow.OwnerId);

            if (document == null)
            {
                throw new DataNotFoundException(nameof(Document), DataNotFoundException.OperationType.Read, workflow.OwnerId);
            }

            var workflowRepo = Uow.GetRepository <DocumentWorkflow>();

            var currentWorkflows = documentWfRepo
                                   .AsQueryable()
                                   .Include(d => d.CurrentStage)
                                   .Where(d => d.OwnerId == workflow.OwnerId && d.IsCurent == true);

            DocumentWorkflow currentWorkflow = null;

            var prevStage = await routeStageRepo.GetByIdAsync(workflow.FromStageId.GetValueOrDefault(0));

            if (prevStage != null)
            {
                currentWorkflow = currentWorkflows.FirstOrDefault(d => d.CurrentStage.Code == prevStage.Code);
            }

            if (isPrevious)
            {
                var previousWorkflow = await workflowRepo.GetByIdAsync(currentWorkflow?.PreviousWorkflowId);

                workflow.PreviousWorkflowId = previousWorkflow?.PreviousWorkflowId;
            }
            else
            {
                workflow.PreviousWorkflowId = currentWorkflow?.Id;
            }

            if (currentWorkflow != null)
            {
                currentWorkflow.IsCurent = false;
                workflowRepo.Update(currentWorkflow);
            }

            workflow.IsCurent = true;
            await workflowRepo.CreateAsync(workflow);

            await Uow.SaveChangesAsync();

            return(workflow.Id);
        }
Exemple #18
0
        public async Task UowAsyncInsert_SingleBlogWithPosts_SuccessfullSave()
        {
            Uow.GetRepository <Blog>().Insert(BlogObjectMother.aDefaultBlog().ToRepository());

            await Uow.SaveChangesAsync();

            var result = Uow.GetRepository <Blog>().GetFirstOrDefault(predicate: x =>
                                                                      x.Title == BlogObjectMother.aDefaultBlog().Title,
                                                                      include: i => i.Include(x => x.Posts));

            Assert.That(result.Title, Is.EqualTo(BlogObjectMother.aDefaultBlog().Title));
            Assert.That(result.Posts, Is.Not.Null);
        }
        public async Task ExecuteAsync(int protectionDocId, List <int> icisIds)
        {
            var protectionDocRepository = Uow.GetRepository <Domain.Entities.ProtectionDoc.ProtectionDoc>();
            var protectionDoc           = await protectionDocRepository.GetByIdAsync(protectionDocId);

            foreach (var id in icisIds)
            {
                protectionDoc.IcisProtectionDocs.Add(new ICISProtectionDoc {
                    ProtectionDocId = protectionDocId, IcisId = id
                });
            }
            await Uow.SaveChangesAsync();
        }
Exemple #20
0
        /// <summary>
        ///  Permanently removes receipt, if it is not finalized and currentUser is receiptManager
        /// </summary>
        /// <param name="receiptId"></param>
        /// <param name="currentUserId"></param>
        /// <returns></returns>
        public async Task <bool> RemoveReceipt(int receiptId, int currentUserId)
        {
            var receipt = await Uow.Receipts.FindReceiptAsync(receiptId);

            if (receipt == null || receipt.IsFinalized || receipt.ReceiptManagerId != currentUserId)
            {
                return(false);
            }
            Uow.Receipts.Remove(receiptId); //Hard delete
            await Uow.SaveChangesAsync();

            return(true);
        }
Exemple #21
0
        public async Task ExecuteAsync(int requestId, List <int> icfemIds)
        {
            var requestRepository = Uow.GetRepository <Domain.Entities.Request.Request>();
            var request           = await requestRepository.GetByIdAsync(requestId);

            foreach (var id in icfemIds)
            {
                request.Icfems.Add(new DicIcfemRequestRelation {
                    DicIcfemId = id, RequestId = requestId
                });
            }
            await Uow.SaveChangesAsync();
        }
        public async Task ExecuteAsync(int requestId, List <int> icisIds)
        {
            var requestRepository = Uow.GetRepository <Domain.Entities.Request.Request>();
            var request           = await requestRepository.GetByIdAsync(requestId);

            foreach (var id in icisIds)
            {
                request.ICISRequests.Add(new ICISRequest {
                    RequestId = requestId, IcisId = id
                });
            }
            await Uow.SaveChangesAsync();
        }
        public async Task Execute(Document document)
        {
            var repo        = Uow.GetRepository <Document>();
            var oldDocument = repo.AsQueryable().Where(d => d.Id == document.Id).Include(d => d.MainAttachment).FirstOrDefault();

            oldDocument.StatusId                       = document.StatusId;
            oldDocument.Status                         = document.Status;
            oldDocument.TypeId                         = document.TypeId;
            oldDocument.AddresseeAddress               = document.AddresseeAddress;
            oldDocument.AddresseeId                    = document.AddresseeId;
            oldDocument.Barcode                        = document.Barcode;
            oldDocument.DepartmentId                   = document.DepartmentId;
            oldDocument.Description                    = document.Description;
            oldDocument.DivisionId                     = document.DivisionId;
            oldDocument.DocumentNum                    = document.DocumentNum;
            oldDocument.IncomingNumber                 = document.IncomingNumber;
            oldDocument.IncomingNumberFilial           = document.IncomingNumberFilial;
            oldDocument.NameEn                         = document.NameEn;
            oldDocument.NameRu                         = document.NameRu;
            oldDocument.NameKz                         = document.NameKz;
            oldDocument.MainAttachmentId               = document.MainAttachmentId;
            oldDocument.OutgoingNumber                 = document.OutgoingNumber;
            oldDocument.ReceiveTypeId                  = document.ReceiveTypeId;
            oldDocument.SendTypeId                     = document.SendTypeId;
            oldDocument.SendingDate                    = document.SendingDate;
            oldDocument.PageCount                      = document.PageCount;
            oldDocument.CopyCount                      = document.CopyCount;
            oldDocument.ControlMark                    = document.ControlMark;
            oldDocument.ControlDate                    = document.ControlDate;
            oldDocument.ResolutionExtensionControlDate = document.ResolutionExtensionControlDate;
            oldDocument.OutOfControl                   = document.OutOfControl;
            oldDocument.DateOutOfControl               = document.DateOutOfControl;
            oldDocument.IsHasPaymentDocument           = document.IsHasPaymentDocument;
            oldDocument.NumberForPayment               = document.NumberForPayment;
            oldDocument.PaymentDate                    = document.PaymentDate;
            oldDocument.PaymentInvoiceId               = document.PaymentInvoiceId;
            oldDocument.IncomingDocumentNumber         = document.IncomingDocumentNumber;
            oldDocument.Comments                       = document.Comments;
            oldDocument.TrackNumber                    = document.TrackNumber;
            oldDocument.IncomingAnswerId               = document.IncomingAnswerId;
            oldDocument.AttachedPaymentsCount          = document.AttachedPaymentsCount;

            if (oldDocument.MainAttachment != null)
            {
                oldDocument.MainAttachment.PageCount = document.PageCount;
                oldDocument.MainAttachment.CopyCount = document.CopyCount;
            }

            repo.Update(oldDocument);
            await Uow.SaveChangesAsync();
        }
Exemple #24
0
        public async Task <int> ChangeLoanStatusAsync(int loanId, LoanStatus newStatus, int userId)
        {
            var loan = await Uow.Loans.FindAsync(loanId);

            if (loan == null)
            {
                return(-1);
            }
            if (loan.LoanGiverId != userId && loan.LoanTakerId != userId)
            {
                return(-1);
            }

            if (loan.Status == LoanStatus.Paid)
            {
                return(-1);                                // Paid loans can't be changed
            }
            if (loan.Status == newStatus)
            {
                return((int)newStatus);
            }

            if (loan.LoanGiverId == userId)
            {
                if (loan.Status == LoanStatus.AwaitingConfirmation && newStatus == LoanStatus.Paid ||
                    loan.Status == LoanStatus.AwaitingConfirmation && newStatus == LoanStatus.Rejected ||
                    loan.Status == LoanStatus.NotPaid && newStatus == LoanStatus.Paid ||
                    loan.Status == LoanStatus.Rejected && newStatus == LoanStatus.Paid)
                {
                    await Uow.Loans.ChangeStatusAsync(loanId, newStatus);

                    await Uow.SaveChangesAsync();

                    return((int)newStatus);
                }

                return(-1);
            }

            if ((loan.Status == LoanStatus.NotPaid || loan.Status == LoanStatus.Rejected) &&
                newStatus == LoanStatus.AwaitingConfirmation)
            {
                await Uow.Loans.ChangeStatusAsync(loanId, newStatus);

                await Uow.SaveChangesAsync();

                return((int)newStatus);
            }

            return(-1);
        }
Exemple #25
0
        public async Task ExecuteAsync(int contractCustomerId)
        {
            var contractCustomerRepo = Uow.GetRepository <ContractCustomer>();
            var contractCustomer     = contractCustomerRepo.GetById(contractCustomerId);

            if (contractCustomer == null)
            {
                throw new DataNotFoundException(nameof(ContractCustomer),
                                                DataNotFoundException.OperationType.Delete, contractCustomerId);
            }

            contractCustomerRepo.Delete(contractCustomer);
            await Uow.SaveChangesAsync();
        }
        public async Task Execute(int documentId)
        {
            var repo     = Uow.GetRepository <Document>();
            var document = repo.GetById(documentId);

            if (document == null)
            {
                throw new DataNotFoundException(nameof(Document), DataNotFoundException.OperationType.Delete, documentId);
            }

            document.IsDeleted = true;

            await Uow.SaveChangesAsync();
        }
Exemple #27
0
        public async Task Execute(CreateBulletinSectionRequestDto requestDto)
        {
            var bulletinSectionRepository = Uow.GetRepository <BulletinSection>();

            var bulletinSection = new BulletinSection
            {
                Name       = requestDto.Name,
                DateCreate = DateTimeOffset.Now
            };

            await bulletinSectionRepository.CreateAsync(bulletinSection);

            await Uow.SaveChangesAsync();
        }
        public async Task ExecuteAsync(int requestId, List <int> colorTzsIds)
        {
            var requestRepository = Uow.GetRepository <Domain.Entities.Request.Request>();
            var request           = await requestRepository.GetByIdAsync(requestId);

            foreach (var colorTzId in colorTzsIds)
            {
                request.ColorTzs.Add(
                    new DicColorTZRequestRelation {
                    ColorTzId = colorTzId, RequestId = requestId
                });
            }
            await Uow.SaveChangesAsync();
        }
Exemple #29
0
        public async Task ExecuteAsync(int protectionDocId, List <int> icfemIds)
        {
            var protectionDocRepository = Uow.GetRepository <Domain.Entities.ProtectionDoc.ProtectionDoc>();
            var protectionDoc           = await protectionDocRepository.GetByIdAsync(protectionDocId);

            foreach (var id in icfemIds)
            {
                protectionDoc.Icfems.Add(
                    new DicIcfemProtectionDocRelation {
                    DicIcfemId = id, ProtectionDocId = protectionDocId
                });
            }
            await Uow.SaveChangesAsync();
        }
Exemple #30
0
        public async Task ExecuteAsync(int protectionDocId, KeyValuePair <string, object>[] pairs)
        {
            if (pairs is null || pairs.Length < 1)
            {
                return;
            }

            var repository       = Uow.GetRepository <ProtectionDoc>();
            var oldProtectionDoc = await NiisAmbientContext.Current.Executor.GetCommand <GetProtectionDocByIdQuery>()
                                   .Process(c => c.ExecuteAsync(protectionDocId));

            foreach (var pair in pairs)
            {
                switch (pair.Key)
                {
                case "validDate":
                {
                    oldProtectionDoc.ValidDate = new DateTimeOffset((DateTime)pair.Value);

                    repository.Update(oldProtectionDoc);
                    await Uow.SaveChangesAsync();
                }
                break;

                case "bulletinId":
                {
                    var relationId = oldProtectionDoc.Bulletins.FirstOrDefault(b => b.IsPublish)?.Id ?? 0;
                    if (relationId != 0)
                    {
                        await NiisAmbientContext.Current.Executor.GetCommand <DeleteProtectionDocBulletinRelationCommand>()
                        .Process(c => c.ExecuteAsync(relationId));
                    }

                    int nextId   = (int)((long)pair.Value);
                    var relation = new ProtectionDocBulletinRelation
                    {
                        BulletinId      = nextId,
                        ProtectionDocId = protectionDocId,
                        IsPublish       = true
                    };
                    await NiisAmbientContext.Current.Executor.GetCommand <CreateProtectionDocBulletinRelationCommand>()
                    .Process(c => c.ExecuteAsync(relation));
                }
                break;

                default:
                    break;
                }
            }
        }