public ComplaintDocument() : base(BusinessObjectType.ComplaintDocument) { this.Lines = new ComplaintDocumentLines(this); Contractor issuer = (Contractor)DependencyContainerManager.Container.Get <ContractorMapper>().LoadBusinessObject(BusinessObjectType.Contractor, new Guid(ConfigurationMapper.Instance.GetConfiguration(SessionManager.User, "document.defaults.issuerId").First().Value.Value)); this.Issuer = issuer; //znajdywanie adresu do faktury Guid billingId = DictionaryMapper.Instance.GetContractorField(ContractorFieldName.Address_Billing).Id.Value; Guid defaultId = DictionaryMapper.Instance.GetContractorField(ContractorFieldName.Address_Default).Id.Value; ContractorAddress billingAddress = issuer.Addresses.Children.Where(a => a.ContractorFieldId == billingId).FirstOrDefault(); Guid?contractorAddressId = null; if (billingAddress != null) { contractorAddressId = billingAddress.Id.Value; } else { contractorAddressId = issuer.Addresses.Children.Where(a => a.ContractorFieldId == defaultId).FirstOrDefault().Id.Value; } this.IssuerAddressId = contractorAddressId.Value; }
public void Delete(Guid id) { Contractor contractor = db.Contractors.Find(id); if (contractor != null) { db.Entry(contractor).State = EntityState.Deleted; } ContractorAddress adress = db.ContractorAddreses.Find(id); if (adress != null) { db.Entry(adress).State = EntityState.Deleted; } }
public CommercialDocumentBase(BusinessObjectType boType) : base(boType) { this.Lines = new CommercialDocumentLines(this); this.VatTableEntries = new CommercialDocumentVatTableEntries(this); DateTime currentDateTime = SessionManager.VolatileElements.CurrentDateTime; //document defaults this.EventDate = currentDateTime; this.IssuePlaceId = new Guid(ConfigurationMapper.Instance.GetSingleConfigurationEntry("document.defaults.issuePlaceId").Value.Value); this.ExchangeDate = currentDateTime.PreviousWorkDay(); this.ExchangeScale = 1; this.ExchangeRate = 1; Contractor issuingPerson = (Contractor)DependencyContainerManager.Container.Get <ContractorMapper>().LoadBusinessObject(BusinessObjectType.Contractor, SessionManager.User.UserId); this.IssuingPerson = issuingPerson; Contractor issuer = (Contractor)DependencyContainerManager.Container.Get <ContractorMapper>().LoadBusinessObject(BusinessObjectType.Contractor, new Guid(ConfigurationMapper.Instance.GetConfiguration(SessionManager.User, "document.defaults.issuerId").First().Value.Value)); this.Issuer = issuer; //znajdywanie adresu do faktury Guid billingId = DictionaryMapper.Instance.GetContractorField(ContractorFieldName.Address_Billing).Id.Value; Guid defaultId = DictionaryMapper.Instance.GetContractorField(ContractorFieldName.Address_Default).Id.Value; ContractorAddress issuerAddress = issuer.Addresses.Children.Where(a => a.ContractorFieldId == billingId).FirstOrDefault(); if (issuerAddress == null) { issuerAddress = issuer.Addresses.Children.Where(a => a.ContractorFieldId == defaultId).FirstOrDefault(); } if (issuerAddress == null) { throw new ClientException(ClientExceptionId.MissingDefaultOrBillingAddress, null, "name:" + issuer.FullName); } this.IssuerAddressId = issuerAddress.Id.Value; }
public void AddOrUpdate(ContractorApiModel contractorInfo, string currentUserName = "") { Contractor contractor = null; ContractorRepository contractorRepository = new ContractorRepository(db); Node node = new NodeRepository(db).GetByAlias(contractorInfo.NodeAlias); ///TODO: throw exception if node alias not found //if (node == null) //{ // throw new NullReferenceException("Node alias is not resolved"); //} Link link = node.Links.Where(c => c.TypeOfSubject == Data.TypeOfSubjectEnum.Contractor && c.NativeId == contractorInfo.NativeId).FirstOrDefault(); if (link == null) { // нет линка - ищем контрагента по кодам contractor = contractorRepository.GetByCodes(contractorInfo); link = new Link() { Node = node, NativeId = contractorInfo.NativeId, TypeOfSubject = Data.TypeOfSubjectEnum.Contractor }; } else { contractor = db.Contractors.Include(c => c.Address).Where(a => a.Id == link.Subject.Id).FirstOrDefault(); } if (contractor == null) { contractor = new Contractor(); contractorRepository.AddOrUpdate(contractor); } else { db.Entry(contractor).State = EntityState.Unchanged; } if (!contractor.Links.Contains(link)) { contractor.Links.Add(link); } if (contractor.Name != contractorInfo.Name) { contractor.Name = contractorInfo.Name; } if (contractor.FullName != contractorInfo.FullName) { contractor.FullName = contractorInfo.FullName; } if (contractor.INN != contractorInfo.INN) { contractor.INN = contractorInfo.INN; } if (contractor.OKPO != contractorInfo.OKPO) { contractor.OKPO = contractorInfo.OKPO; } if (contractor.VATNumber != contractorInfo.VATNumber) { contractor.VATNumber = contractorInfo.VATNumber; } if (contractor.CountryOfRegistration != contractorInfo.CountryOfRegistration) { contractor.CountryOfRegistration = contractorInfo.CountryOfRegistration; } if (contractor.TypeOfCounterparty != contractorInfo.TypeOfCounterparty) { contractor.TypeOfCounterparty = contractorInfo.TypeOfCounterparty; } if (contractor.IsBranch != contractorInfo.IsBranch) { contractor.IsBranch = contractorInfo.IsBranch; } if (contractor.IsBranch) { Contractor headContractor = contractorRepository.GetByNativeId(contractorInfo.HeadContractorNativeId, contractorInfo.NodeAlias); if (contractor.HeadContractor != headContractor) { contractor.HeadContractor = headContractor; } if (contractor.BranchCode != contractorInfo.BranchCode) { contractor.BranchCode = contractorInfo.BranchCode; } } // Address ContractorAddress address = contractor.Address; if (address == null) { address = new ContractorAddress(); contractor.Address = address; db.Entry(address).State = EntityState.Added; } else { db.Entry(address).State = EntityState.Unchanged; } if ((!string.IsNullOrEmpty(contractorInfo.Street)) && (address.Street != contractorInfo.Street)) { address.Street = contractorInfo.Street; } if ((!string.IsNullOrEmpty(contractorInfo.House)) && (address.House != contractorInfo.House)) { address.House = contractorInfo.House; } if ((!string.IsNullOrEmpty(contractorInfo.Flat)) && (address.Flat != contractorInfo.Flat)) { address.Flat = contractorInfo.Flat; } if ((!string.IsNullOrEmpty(contractorInfo.City)) && (address.City != contractorInfo.City)) { address.City = contractorInfo.City; } if ((!string.IsNullOrEmpty(contractorInfo.District)) && (address.District != contractorInfo.District)) { address.District = contractorInfo.District; } if ((!string.IsNullOrEmpty(contractorInfo.Region)) && (address.Region != contractorInfo.Region)) { address.Region = contractorInfo.Region; } if ((!string.IsNullOrEmpty(contractorInfo.PostalCode)) && (address.PostalCode != contractorInfo.PostalCode)) { address.PostalCode = contractorInfo.PostalCode; } if ((!string.IsNullOrEmpty(contractorInfo.Country)) && (address.Country != contractorInfo.Country)) { address.Country = contractorInfo.Country; } if ((!string.IsNullOrEmpty(contractorInfo.StringRepresentedAddress)) && (address.StringRepresentedAddress != contractorInfo.StringRepresentedAddress)) { address.StringRepresentedAddress = contractorInfo.StringRepresentedAddress; } // History HistoryEntry historyEntry = new HistoryEntry(); historyEntry.User = contractorInfo.User; historyEntry.Node = node; historyEntry.SubjectSnapshot = contractor; contractor.Histories.Add(historyEntry); }
public void AddOrUpdate(ContractorViewModel model, string currentUserName) { Contractor contractor = db.Contractors.Include(c => c.Address).Where(a => a.Id == model.Id).FirstOrDefault(); if (contractor == null) { contractor = new Contractor(); db.Entry(contractor).State = EntityState.Added; } else { db.Entry(contractor).State = EntityState.Unchanged; } if (contractor.Name != model.Name) { contractor.Name = model.Name; } if (contractor.FullName != model.FullName) { contractor.FullName = model.FullName; } if (contractor.INN != model.INN) { contractor.INN = model.INN; } if (contractor.OKPO != model.OKPO) { contractor.OKPO = model.OKPO; } if (contractor.VATNumber != model.VATNumber) { contractor.VATNumber = model.VATNumber; } if (contractor.CountryOfRegistration != model.CountryOfRegistration) { contractor.CountryOfRegistration = model.CountryOfRegistration; } if (contractor.TypeOfCounterparty != model.TypeOfCounterparty) { contractor.TypeOfCounterparty = model.TypeOfCounterparty; } if (contractor.IsBranch != model.IsBranch) { contractor.IsBranch = model.IsBranch; } if (contractor.HeadContractor != model.HeadContractor) { contractor.HeadContractor = model.HeadContractor; } if (contractor.BranchCode != model.BranchCode) { contractor.BranchCode = model.BranchCode; } // Address ContractorAddress address = contractor.Address; if (address == null) { address = new ContractorAddress(); contractor.Address = address; db.Entry(address).State = EntityState.Added; } else { db.Entry(address).State = EntityState.Unchanged; } if (address.Street != model.Street) { address.Street = model.Street; } if (address.House != model.House) { address.House = model.House; } if (address.Flat != model.Flat) { address.Flat = model.Flat; } if (address.City != model.City) { address.City = model.City; } if (address.District != model.District) { address.District = model.District; } if (address.Region != model.Region) { address.Region = model.Region; } if (address.PostalCode != model.PostalCode) { address.PostalCode = model.PostalCode; } if (address.Country != model.Country) { address.Country = model.Country; } if (address.StringRepresentedAddress != model.StringRepresentedAddress) { address.StringRepresentedAddress = model.StringRepresentedAddress; } // History HistoryEntry historyEntry = new HistoryEntry(); historyEntry.User = currentUserName; historyEntry.SubjectSnapshot = contractor; contractor.Histories.Add(historyEntry); }