public void RegisterContract(Guid contractId) { var contract = AppContext.Contracts .Include(e => e.ManufacturerOrganization) .Include(e => e.ApplicantOrganization) .Include(e => e.HolderOrganization) .Include(e => e.PayerOrganization) .Include(e => e.PayerTranslationOrganization) .FirstOrDefault(e => e.Id == contractId); contract.StatusId = DictionaryHelper.GetDicIdByCode(Dictionary.ContractStatus.DicCode, DataModel.Contract.StatusActive); //кидаем организации в историю var histProducer = (Organization)contract.ManufacturerOrganization.Clone(); var histApplicant = (Organization)contract.ApplicantOrganization.Clone(); var histHolder = contract.HolderOrganizationId != null ? (Organization)contract.HolderOrganization.Clone() : null; var histPayer = (Organization)contract.PayerOrganization.Clone(); var histPayerTranslation = (Organization)contract.PayerTranslationOrganization.Clone(); var origProducerId = contract.ManufacturerOrganizationId; var origApplicantId = contract.ApplicantOrganizationId; var origHolderId = contract.HolderOrganizationId; var origPayerId = contract.PayerOrganizationId; var origPayerTranslationId = contract.PayerTranslationOrganizationId; AppContext.Organizations.Add(histApplicant); contract.ApplicantOrganizationId = histApplicant.Id; contract.ApplicantOrganization = histApplicant; if (origProducerId != origHolderId) { AppContext.Organizations.Add(histProducer); contract.ManufacturerOrganizationId = histProducer.Id; contract.ManufacturerOrganization = histProducer; } if (histHolder != null) { AppContext.Organizations.Add(histHolder); contract.HolderOrganizationId = histHolder.Id; contract.HolderOrganization = histHolder; } if (origHolderId == origProducerId) { contract.ManufacturerOrganizationId = histHolder.Id; contract.ManufacturerOrganization = histHolder; } if (origPayerId != origProducerId && origPayerId != origHolderId && origPayerId != origApplicantId) { AppContext.Organizations.Add(histPayer); contract.PayerOrganizationId = histPayer.Id; contract.PayerOrganization = histPayer; } if (origPayerId == origProducerId) { contract.PayerOrganizationId = histProducer.Id; contract.PayerOrganization = histProducer; } else if (origPayerId == origApplicantId) { contract.PayerOrganizationId = histApplicant.Id; contract.PayerOrganization = histApplicant; } else if (origPayerId == origHolderId) { contract.PayerOrganizationId = histHolder.Id; contract.PayerOrganization = histHolder; } if (origPayerTranslationId != origProducerId && origPayerTranslationId != origHolderId && origPayerTranslationId != origApplicantId) { AppContext.Organizations.Add(histPayerTranslation); contract.PayerTranslationOrganizationId = histPayerTranslation.Id; contract.PayerOrganization = histPayerTranslation; } if (origPayerTranslationId == origProducerId) { contract.PayerTranslationOrganizationId = histProducer.Id; contract.PayerTranslationOrganization = histProducer; } else if (origPayerTranslationId == origApplicantId) { contract.PayerTranslationOrganizationId = histApplicant.Id; contract.PayerTranslationOrganization = histApplicant; } else if (origPayerTranslationId == origHolderId) { contract.PayerTranslationOrganizationId = histHolder.Id; contract.PayerTranslationOrganization = histHolder; } AppContext.SaveChanges(); var contract1C = new I1c_exp_Contracts() { Id = contract.Id, ContractDate = contract.ContractDate.Value, ContractNumber = contract.Number, ContractUrl = string.Format("{0}FileStorage/Download?id={1}&fileType=Contract", ConfigurationManager.AppSettings["ServerBaseUrl"], contract.Id) }; AppContext.I1c_exp_Contracts.Add(contract1C); AppContext.SaveChanges(); }
public async Task <ActionResult> GetDicIdByCode(string dicType, string code) { var val = DictionaryHelper.GetDicIdByCode(dicType, code); return(Json(val, JsonRequestBehavior.AllowGet)); }
public ActionResult LoadContract(Guid id) { db.Configuration.ProxyCreationEnabled = false; db.Configuration.LazyLoadingEnabled = false; var project = db.Contracts.Include(e => e.ContractStatus).Include(e => e.HolderType).FirstOrDefault(o => o.Id == id); Organization manufacture; Organization applicant; Organization holder; Organization payer; Organization payerTranslation; Contract holderContract = new Contract(); if (project == null) { var holderType = DictionaryHelper.GetDicItemByCode(Dictionary.ContractHolderType.DicCode, Dictionary.ContractHolderType.Producer); project = new Contract() { Id = id, ManufacturerOrganizationId = Guid.NewGuid(), ApplicantOrganizationId = Guid.NewGuid(), HolderOrganizationId = Guid.NewGuid(), PayerOrganizationId = Guid.NewGuid(), PayerTranslationOrganizationId = Guid.NewGuid(), Type = 1, CreatedDate = DateTime.Now, DoverennostCreatedDate = DateTime.Now, DoverennostExpiryDate = DateTime.Now, StartDate = DateTime.Now, EndDate = DateTime.Now, HolderTypeId = holderType.Id, HolderTypeCode = holderType.Code, OwnerId = UserHelper.GetCurrentEmployee().Id, StatusId = DictionaryHelper.GetDicIdByCode(Dictionary.ContractStatus.DicCode, Database.DataModel.Contract.StatusNew) }; manufacture = new Organization() { Id = project.ManufacturerOrganizationId.Value, Type = 21, DocDate = DateTime.Now, DocExpiryDate = DateTime.Now }; applicant = new Organization() { Id = project.ApplicantOrganizationId.Value, Type = 22, DocDate = DateTime.Now, DocExpiryDate = DateTime.Now }; holder = new Organization() { Id = project.HolderOrganizationId.Value, Type = 23, DocDate = DateTime.Now, DocExpiryDate = DateTime.Now }; payer = new Organization() { Id = project.PayerOrganizationId.Value, Type = 24, DocDate = DateTime.Now, DocExpiryDate = DateTime.Now }; payerTranslation = new Organization() { Id = project.PayerTranslationOrganizationId.Value, Type = 24, DocDate = DateTime.Now, DocExpiryDate = DateTime.Now }; } else { manufacture = db.Organizations.FirstOrDefault(o => o.Id == project.ManufacturerOrganizationId); applicant = db.Organizations.FirstOrDefault(o => o.Id == project.ApplicantOrganizationId); holder = db.Organizations.FirstOrDefault(o => o.Id == project.HolderOrganizationId); payer = db.Organizations.FirstOrDefault(o => o.Id == project.PayerOrganizationId); payerTranslation = db.Organizations.FirstOrDefault(o => o.Id == project.PayerTranslationOrganizationId); if (project.ContractId != null) { holderContract = db.Contracts.FirstOrDefault(m => m.Id == project.ContractId); } project.HolderTypeCode = project.HolderType.Code; } return(Content(JsonConvert.SerializeObject(new RequestModel { Contract = project, Manufacture = manufacture, Applicant = applicant, Holder = holder, Payer = payer, PayerTranslation = payerTranslation, HolderContract = holderContract, }, Formatting.Indented, new JsonSerializerSettings() { DateFormatString = "yyyy-MM-ddTHH:mm:ss.fffZ" }))); }