예제 #1
0
        public void Execute(int protectionDocId, List <ProtectionDocCustomer> customers)
        {
            var protectionDocRepository = Uow.GetRepository <ProtectionDoc>();
            var protectionDoc           = protectionDocRepository.AsQueryable()
                                          .Include(pd => pd.Type)
                                          .FirstOrDefault(pd => pd.Id == protectionDocId);

            if (protectionDoc == null)
            {
                throw new DataNotFoundException(nameof(ProtectionDoc), DataNotFoundException.OperationType.Read, protectionDocId);
            }

            string roleCode;

            if (protectionDoc.Type.Code == DicProtectionDocTypeCodes.RequestTypeTrademarkCode ||
                protectionDoc.Type.Code == DicProtectionDocTypeCodes.RequestTypeNameOfOriginCode ||
                protectionDoc.Type.Code == DicProtectionDocTypeCodes.ProtectionDocTypeTrademarkCode ||
                protectionDoc.Type.Code == DicProtectionDocTypeCodes.ProtectionDocTypeNameOfOriginCode)
            {
                roleCode = DicCustomerRoleCodes.Owner;
            }
            else
            {
                roleCode = DicCustomerRoleCodes.PatentOwner;
            }

            var roleRepository = Uow.GetRepository <DicCustomerRole>();
            var owner          = roleRepository.AsQueryable().FirstOrDefault(r => r.Code == roleCode);

            if (owner == null)
            {
                throw new DataNotFoundException(nameof(DicCustomerRole), DataNotFoundException.OperationType.Read, roleCode);
            }

            var protectionDocCustomerRepository = Uow.GetRepository <ProtectionDocCustomer>();

            foreach (var customer in customers)
            {
                var customerRole = roleRepository.GetById(customer.CustomerRoleId);
                customer.ProtectionDocId = protectionDocId;
                if (customerRole.Code == DicCustomerRoleCodes.Declarant)
                {
                    var patentOwner = new ProtectionDocCustomer
                    {
                        CustomerId      = customer.CustomerId,
                        ProtectionDocId = protectionDocId,
                        Address         = customer.Address,
                        CustomerRoleId  = owner.Id,
                        Phone           = customer.Phone,
                        PhoneFax        = customer.PhoneFax,
                        MobilePhone     = customer.MobilePhone,
                        Email           = customer.Email
                    };
                    protectionDocCustomerRepository.Create(patentOwner);
                }
            }
            protectionDocCustomerRepository.CreateRange(customers);

            Uow.SaveChanges();
        }
        public async Task ExecuteAsync(ProtectionDocCustomer protectionDocCustomer)
        {
            var repo = Uow.GetRepository <ProtectionDocCustomer>();

            repo.Update(protectionDocCustomer);
            await Uow.SaveChangesAsync();
        }
        /// <summary>
        /// Получает идентификатор адресата для переписки по идентификатору охранного документа.
        /// </summary>
        /// <param name="protectionDocId">Идентификатор охранного документа.</param>
        /// <returns>Идентификатор адресата для переписки.</returns>
        private async Task <int?> GetAddresseeIdByProtectionDocId(int protectionDocId)
        {
            ProtectionDoc protectionDoc = await Executor
                                          .GetQuery <GetProtectionDocByIdWithCustomersAndCustomerRolesQuery>()
                                          .Process(query => query.ExecuteAsync(protectionDocId));

            if (protectionDoc is null)
            {
                throw new DataNotFoundException(nameof(ProtectionDoc),
                                                DataNotFoundException.OperationType.Read, protectionDocId);
            }

            ProtectionDocCustomer addressee = protectionDoc.ProtectionDocCustomers
                                              .FirstOrDefault(customer => customer.CustomerRole.Code == DicCustomerRoleCodes.Correspondence);

            return(addressee?.CustomerId);
        }