/// <summary> /// Cохранение изменений /// </summary> /// <param name="code"></param> /// <param name="modelId">id</param> /// <param name="userId">id пользователя</param> /// <param name="recordId">id записи</param> /// <param name="fieldName">наименование поля</param> /// <param name="fieldValue">значение</param> /// <param name="fieldDisplay">значение</param> /// <returns></returns> public SubUpdateField UpdateModel(string code, int typeId, string modelId, string userId, long?recordId, string fieldName, string fieldValue, string fieldDisplay) { bool isNew = false; var model = GetById(modelId); if (model == null) { model = new OBK_AssessmentDeclaration { EmployeeId = UserHelper.GetCurrentEmployee().Id, Type_Id = GetObkRefTypes(typeId.ToString()).Id, Id = new Guid(modelId), CreatedDate = DateTime.Now, StatusId = CodeConstManager.STATUS_DRAFT_ID, CertificateDate = DateTime.Now, IsDeleted = false }; isNew = true; } switch (code) { case "main": { return(UpdateMain(isNew, model, fieldName, fieldValue, userId, fieldDisplay)); } } return(null); }
/// <summary> /// /// </summary> /// <param name="declaration"></param> /// <returns></returns> public OBK_AssessmentDeclaration Update(OBK_AssessmentDeclaration declaration) { var attachedEntity = AppContext.Set <OBK_AssessmentDeclaration>().Find(declaration.Id); AppContext.Entry(attachedEntity).CurrentValues.SetValues(declaration); AppContext.Commit(true); return(declaration); }
public ActionResult SendToOP(OBK_AssessmentDeclaration declaration) { var declarationStage = repo.OBK_AssessmentStage.FirstOrDefault(x => x.DeclarationId == declaration.Id && x.StageId == 15); if (declarationStage == null) { declarationStage = new OBK_AssessmentStage { Id = Guid.NewGuid(), StageId = 15, StageStatusId = 2, DeclarationId = declaration.Id, StartDate = DateTime.Now }; repo.OBK_AssessmentStage.Add(declarationStage); } else { declarationStage.StageStatusId = 2; declarationStage.StartDate = DateTime.Now; } var executor = repo.OBK_AssessmentStageExecutors.FirstOrDefault(x => x.AssessmentStageId == declarationStage.Id && x.ExecutorType == 2); if (executor == null) { executor = new OBK_AssessmentStageExecutors { AssessmentStageId = declarationStage.Id, ExecutorId = UserHelper.GetCurrentEmployee().Id, ExecutorType = 2 }; repo.OBK_AssessmentStageExecutors.Add(executor); } else { executor.ExecutorId = UserHelper.GetCurrentEmployee().Id; } var stage = repo.OBK_AssessmentStage.FirstOrDefault(x => x.DeclarationId == declaration.Id && x.StageId == 2); stage.StageStatusId = 13; stage.EndDate = DateTime.Now; stage.FactEndDate = stage.EndDate; declaration = repo.OBK_AssessmentDeclaration.FirstOrDefault(x => x.Id == declaration.Id); var status = repo.OBK_Ref_Status.FirstOrDefault(x => x.Code == "30"); declaration.StatusId = status.Id; repo.SaveChanges(); return(Json(new { isSuccess = true })); }
private SubUpdateField UpdateProduct(OBK_AssessmentDeclaration model, long?recordId, string fieldName, string fieldValue, string userId, string fieldDisplay) { OBK_RS_Products entity = null; if (recordId > 0) { entity = AppContext.Set <OBK_RS_Products>().FirstOrDefault(e => e.Id == recordId); } var property = entity.GetType().GetProperty(fieldName); if (property != null) { var t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType; object safeValue; if (string.IsNullOrEmpty(fieldValue)) { fieldValue = null; } if (t == typeof(Guid)) { safeValue = fieldValue == null ? null : Convert.ChangeType(new Guid(fieldValue), t); } else { safeValue = fieldValue == null ? null : Convert.ChangeType(fieldValue, t); } property.SetValue(entity, safeValue, null); } if (entity.Id == 0) { AppContext.OBK_RS_Products.Add(entity); } AppContext.SaveChanges(); SaveHistoryField(model.Id, fieldName, fieldValue, new Guid(userId), fieldDisplay); var subUpdateField = new SubUpdateField(); subUpdateField.ModelId = model.ObjectId; subUpdateField.RecordId = entity.Id; return(subUpdateField); }
/// <summary> /// создание дубликата /// </summary> /// <param name="id"></param> /// <param name="guid"></param> /// <returns></returns> public OBK_AssessmentDeclaration DublicateAssessmentDeclaration(string id, Guid guid) { var oldModel = GetById(id); if (oldModel == null) { return(null); } var model = new OBK_AssessmentDeclaration { Id = Guid.NewGuid(), EmployeeId = guid, StatusId = CodeConstManager.STATUS_DRAFT_ID, CreatedDate = DateTime.Now, CertificateGMP = oldModel.CertificateGMP, CertificateNumber = oldModel.CertificateNumber, AssuranceCheck = oldModel.AssuranceCheck, OrderCheck = oldModel.OrderCheck, StabilityCheck = oldModel.StabilityCheck, PaymentCheck = oldModel.PaymentCheck, Type_Id = oldModel.Type_Id, Contract_Id = oldModel.Contract_Id, CertificateDate = oldModel.CertificateDate, CertificateGMPCheck = oldModel.CertificateGMPCheck, InvoiceRu = oldModel.InvoiceRu, InvoiceKz = oldModel.InvoiceKz, InvoiceDate = oldModel.InvoiceDate, InvoiceContractRu = oldModel.InvoiceContractRu, InvoiceContractKz = oldModel.InvoiceContractKz, InvoiceAgentLastName = oldModel.InvoiceAgentLastName, InvoiceAgentFirstName = oldModel.InvoiceAgentFirstName, InvoiceAgentMiddelName = oldModel.InvoiceAgentMiddelName, InvoiceAgentPositionName = oldModel.InvoiceAgentPositionName, IsDeleted = false, DesignDate = oldModel.DesignDate, ObkContracts = oldModel.ObkContracts }; AppContext.OBK_AssessmentDeclaration.Add(model); AppContext.SaveChanges(); return(model); }
public ActionResult EditContract(string id) { var repository = new SafetyAssessmentRepository(); var contract = repository.GetContractById(new Guid(id)); var model = repository.FindDeclarationByContract(new Guid(id)); if (model == null) { model = new OBK_AssessmentDeclaration { EmployeeId = UserHelper.GetCurrentEmployee().Id, Type_Id = contract.OBK_Ref_Type.Id, Id = Guid.NewGuid(), CreatedDate = DateTime.Now, StatusId = CodeConstManager.STATUS_DRAFT_ID, CertificateDate = DateTime.Now, Contract_Id = contract.Id, IsDeleted = false, CertificateGMPCheck = contract.OBK_Ref_Type.Code == CodeConstManager.OBK_SA_DECLARATION }; repository.SaveAssessmentDeclaration(model); } return(Json(model.Id, JsonRequestBehavior.AllowGet)); }
private SubUpdateField UpdateMain(bool isNew, OBK_AssessmentDeclaration model, string fieldName, string fieldValue, string userId, string fieldDisplay) { var property = model.GetType().GetProperty(fieldName); if (property != null) { var t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType; object safeValue; if (string.IsNullOrEmpty(fieldValue)) { fieldValue = null; } if (t == typeof(Guid)) { safeValue = fieldValue == null ? null : Convert.ChangeType(new Guid(fieldValue), t); } else { safeValue = fieldValue == null ? null : Convert.ChangeType(fieldValue, t); } property.SetValue(model, safeValue, null); } if (isNew) { AppContext.OBK_AssessmentDeclaration.Add(model); AppContext.SaveChanges(); } SaveHistoryField(model.Id, fieldName, fieldValue, new Guid(userId), fieldDisplay); var subUpdateField = new SubUpdateField(); subUpdateField.ModelId = model.ObjectId; return(subUpdateField); }
public virtual ActionResult GetContract(Guid id) { var contract = new SafetyAssessmentRepository().GetContractById(id); if (contract == null) { return(Json(new { isSuccess = false })); } var products = new SafetyAssessmentRepository().GetRsProductsAndSeries(contract.Id); var result = new OBK_AssessmentDeclaration(); var resultProducts = new List <OBK_RS_Products>(); foreach (var product in products) { var prod = new OBK_RS_Products(); prod.Id = product.Id; prod.NameRu = product.NameRu; prod.NameKz = product.NameKz; prod.ProducerNameRu = product.ProducerNameRu; prod.ProducerNameKz = product.ProducerNameKz; prod.CountryNameRu = product.CountryNameRu; prod.CountryNameKZ = product.CountryNameKZ; prod.DrugFormFullName = product.DrugFormFullName; prod.DrugFormFullNameKz = product.DrugFormFullNameKz; prod.DrugFormBoxCount = product.DrugFormBoxCount; //prod.TnvedCode = product.TnvedCode; //prod.KpvedCode = product.KpvedCode; prod.CurrencyId = product.CurrencyId; prod.Price = product.Price; prod.RegTypeId = product.RegTypeId; prod.RegNumber = product.RegNumber; prod.RegisterId = product.RegisterId; prod.RegNumberKz = product.RegNumberKz; prod.RegDate = product.RegDate; prod.ExpirationDate = product.ExpirationDate; prod.NdName = product.NdName; prod.NdNumber = product.NdNumber; prod.Dimension = product.Dimension; prod.ExpertisePlace = product.ExpertisePlace; foreach (var productSeries in product.OBK_Procunts_Series) { var prodSeries = new OBK_Procunts_Series(); prodSeries.Id = productSeries.Id; prodSeries.Series = productSeries.Series; prodSeries.SeriesStartdate = productSeries.SeriesStartdate; prodSeries.SeriesEndDate = productSeries.SeriesEndDate; prodSeries.SeriesParty = productSeries.SeriesParty; prodSeries.SeriesShortNameRu = productSeries.sr_measures.short_name; var obkStageExpDocumentSeries = new SafetyAssessmentRepository().GetStageExpDocument(prodSeries.Id); if (obkStageExpDocumentSeries != null) { prodSeries.ExpId = obkStageExpDocumentSeries.Id; prodSeries.ProductSeriesId = obkStageExpDocumentSeries.ProductSeriesId; prodSeries.ExpResult = obkStageExpDocumentSeries.ExpResult ? "True" : "False"; prodSeries.ExpResultTitle = obkStageExpDocumentSeries.ExpResult ? "Соответствует требованиям" : "Не соответствует требованиям"; prodSeries.ExpStartDate = string.Format("{0:dd.MM.yyyy}", obkStageExpDocumentSeries.ExpStartDate); prodSeries.ExpEndDate = string.Format("{0:dd.MM.yyyy}", obkStageExpDocumentSeries.ExpEndDate); prodSeries.ExpReasonNameRu = obkStageExpDocumentSeries.ExpReasonNameRu; prodSeries.ExpReasonNameKz = obkStageExpDocumentSeries.ExpReasonNameKz; prodSeries.ExpProductNameRu = obkStageExpDocumentSeries.ExpProductNameRu; prodSeries.ExpProductNameKz = obkStageExpDocumentSeries.ExpProductNameKz; prodSeries.ExpNomenclatureRu = obkStageExpDocumentSeries.ExpNomenclatureRu; prodSeries.ExpNomenclatureKz = obkStageExpDocumentSeries.ExpNomenclatureKz; prodSeries.ExpAddInfoRu = obkStageExpDocumentSeries.ExpAddInfoRu; prodSeries.ExpAddInfoKz = obkStageExpDocumentSeries.ExpAddInfoKz; prodSeries.ExpConclusionNumber = obkStageExpDocumentSeries.ExpConclusionNumber; prodSeries.ExpBlankNumber = obkStageExpDocumentSeries.ExpBlankNumber; prodSeries.ExpApplication = obkStageExpDocumentSeries.ExpApplication; prodSeries.ExpApplicationNumber = obkStageExpDocumentSeries.ExpApplicationNumber; } prod.OBK_Procunts_Series.Add(prodSeries); } foreach (var mtPart in product.OBK_MtPart) { var mtParts = new OBK_MtPart(); mtParts.PartNumber = mtPart.PartNumber; mtParts.Model = mtPart.Model; mtParts.Specification = mtPart.Specification; mtParts.ProducerName = mtPart.ProducerName; mtParts.CountryName = mtPart.CountryName; mtParts.Name = mtPart.Name; prod.OBK_MtPart.Add(mtParts); } resultProducts.Add(prod); } result.ObkRsProductses = resultProducts; return(Json(new { isSuccess = true, result })); }
public virtual ActionResult GetContract(Guid id) { var contract = new SafetyAssessmentRepository().GetContractById(id); if (contract == null) { return(Json(new { isSuccess = false })); } var declarant = new SafetyAssessmentRepository().GetDeclarantById(contract.DeclarantId); var declarantContact = new SafetyAssessmentRepository().GetDeclarantContactById(contract.DeclarantContactId); var products = new SafetyAssessmentRepository().GetRsProductsAndSeries(contract.Id); var result = new OBK_AssessmentDeclaration(); result.StartDate = string.Format("{0:dd.MM.yyyy}", contract.StartDate); result.EndDate = string.Format("{0:dd.MM.yyyy}", contract.EndDate); result.OrganizationFormId = declarant?.OrganizationFormId ?? null; result.NameKz = declarant?.NameKz ?? "нет данных"; result.NameRu = declarant?.NameRu ?? "нет данных"; result.NameEn = declarant?.NameEn ?? "нет данных"; result.ChiefLastName = declarantContact?.BossLastName ?? "нет данных"; result.ChiefFirstName = declarantContact?.BossFirstName ?? "нет данных"; result.ChiefMiddleName = declarantContact?.BossMiddleName ?? "нет данных"; result.ChiefPosition = declarantContact?.BossPosition ?? "нет данных"; result.AddressFact = declarantContact?.AddressFact ?? "нет данных"; result.AddressLegal = declarantContact?.AddressLegalRu ?? "нет данных"; result.Phone = declarantContact?.Phone ?? "нет данных"; result.Email = declarantContact?.Email ?? "нет данных"; result.BankBik = declarantContact?.BankBik ?? "нет данных"; result.BankIik = declarantContact?.BankIik ?? "нет данных"; result.BankName = declarantContact?.BankNameRu ?? "нет данных"; result.CountryId = declarant?.CountryId ?? null; result.CurrencyId = declarantContact?.CurrencyId ?? null; var resultProducts = new List <OBK_RS_Products>(); foreach (var product in products) { var prod = new OBK_RS_Products(); prod.Id = product.Id; prod.NameRu = product.NameRu; prod.NameKz = product.NameKz; prod.ProducerNameRu = product.ProducerNameRu; prod.ProducerNameKz = product.ProducerNameKz; prod.CountryNameRu = product.CountryNameRu; prod.CountryNameKZ = product.CountryNameKZ; prod.TnvedCode = product.TnvedCode; prod.KpvedCode = product.KpvedCode; prod.Price = product.Price; prod.CurrencyId = product.CurrencyId; prod.DrugFormBoxCount = product.DrugFormBoxCount; prod.DrugFormFullName = product.DrugFormFullName; prod.RegTypeId = product.RegTypeId; foreach (var productSeries in product.OBK_Procunts_Series) { var prodSeries = new OBK_Procunts_Series(); prodSeries.Id = productSeries.Id; prodSeries.Series = productSeries.Series; prodSeries.SeriesStartdate = productSeries.SeriesStartdate; prodSeries.SeriesEndDate = productSeries.SeriesEndDate; prodSeries.SeriesParty = productSeries.SeriesParty; prodSeries.SeriesShortNameRu = productSeries.sr_measures.short_name; prod.OBK_Procunts_Series.Add(prodSeries); } foreach (var mtPart in product.OBK_MtPart) { var mtParts = new OBK_MtPart(); mtParts.PartNumber = mtPart.PartNumber; mtParts.Model = mtPart.Model; mtParts.Specification = mtPart.Specification; mtParts.ProducerName = mtPart.ProducerName; mtParts.CountryName = mtPart.CountryName; mtParts.Name = mtPart.Name; prod.OBK_MtPart.Add(mtParts); } resultProducts.Add(prod); } result.ObkRsProductses = resultProducts; return(Json(new { isSuccess = true, result })); }
/// <summary> /// подача заявления /// </summary> /// <returns></returns> public ActionResult Create(string type) { var model = new OBK_AssessmentDeclaration { Id = Guid.NewGuid(), EmployeeId = UserHelper.GetCurrentEmployee().Id, StatusId = CodeConstManager.STATUS_DRAFT_ID, ObkContracts = new OBK_Contract(), ObkRsProductses = new List <OBK_RS_Products>() }; model.CertificateDate = null; model.CreatedDate = DateTime.Now; var safetyRepository = new SafetyAssessmentRepository(false); if (type == CodeConstManager.OBK_SA_SERIAL) { ViewData["TypeList"] = new SelectList(safetyRepository.GetObkRefTypes(), "Id", "NameRu", model.Type_Id = safetyRepository.GetObkRefTypes(CodeConstManager.OBK_SA_SERIAL).Id); } if (type == CodeConstManager.OBK_SA_PARTY) { ViewData["TypeList"] = new SelectList(safetyRepository.GetObkRefTypes(), "Id", "NameRu", model.Type_Id = safetyRepository.GetObkRefTypes(CodeConstManager.OBK_SA_PARTY).Id); } if (type == CodeConstManager.OBK_SA_DECLARATION) { ViewData["TypeList"] = new SelectList(safetyRepository.GetObkRefTypes(), "Id", "NameRu", model.Type_Id = safetyRepository.GetObkRefTypes(CodeConstManager.OBK_SA_DECLARATION).Id); } ViewData["ContractList"] = new SelectList(safetyRepository.GetActiveContractListWithInfo(model.EmployeeId, safetyRepository.GetObkRefTypes(type).Id), "Id", "ContractInfo", model.Contract_Id); var repository = new ReadOnlyDictionaryRepository(); //огранизационная форма var orgForm = safetyRepository.GetOrganizationForm(); ViewData["OrganizationForm"] = new SelectList(orgForm, "Id", "Name"); var certType = safetyRepository.GetCertificateType(); ViewData["CertificateType"] = new SelectList(certType, "Id", "NameRu"); //Наличие сертификата GMP var booleans = repository.GetCertificateGMPCheck(); ViewData["IsGMPList"] = new SelectList(booleans, "CertificateGMPCheck", "NameRu", model.CertificateGMPCheck); //справочник стран var countries = safetyRepository.GetCounties(); ViewData["Counties"] = new SelectList(countries, "Id", "Name"); //Валюта var currency = safetyRepository.GetObkCurrencies(); ViewData["Courrency"] = new SelectList(currency, "Id", "Name"); return(View(model)); }
private void FillDeclarationControl(OBK_AssessmentDeclaration model) { var safetyRepository = new SafetyAssessmentRepository(); ViewData["ContractList"] = new SelectList(safetyRepository.GetActiveContractListWithInfo(model.EmployeeId, model.Type_Id), "Id", "ContractInfo", model.Contract_Id); if (model.Type_Id == int.Parse(CodeConstManager.OBK_SA_SERIAL)) { ViewData["TypeList"] = new SelectList(safetyRepository.GetObkRefTypes(), "Id", "NameRu", model.Type_Id = safetyRepository.GetObkRefTypes(CodeConstManager.OBK_SA_SERIAL).Id); } if (model.Type_Id == int.Parse(CodeConstManager.OBK_SA_PARTY)) { ViewData["TypeList"] = new SelectList(safetyRepository.GetObkRefTypes(), "Id", "NameRu", model.Type_Id = safetyRepository.GetObkRefTypes(CodeConstManager.OBK_SA_PARTY).Id); } if (model.Type_Id == int.Parse(CodeConstManager.OBK_SA_DECLARATION)) { ViewData["TypeList"] = new SelectList(safetyRepository.GetObkRefTypes(), "Id", "NameRu", model.Type_Id = safetyRepository.GetObkRefTypes(CodeConstManager.OBK_SA_DECLARATION).Id); } if (model.Contract_Id != null) { var contract = safetyRepository.GetContractById(model.Contract_Id); var declarant = safetyRepository.GetDeclarantById(contract.DeclarantId); var declarantContact = safetyRepository.GetDeclarantContactById(contract.DeclarantContactId); var products = safetyRepository.GetRsProductsAndSeries(contract.Id); //справочник стран var countries = safetyRepository.GetCounties(); if (declarant?.CountryId == null) { ViewData["Counties"] = new SelectList(countries, "Id", "Name"); } else { ViewData["Counties"] = new SelectList(countries, "Id", "Name", model.CountryId = declarant.CountryId); } //Валюта var currency = safetyRepository.GetObkCurrencies(); if (declarantContact?.CurrencyId == null) { ViewData["Courrency"] = new SelectList(currency, "Id", "Name"); } else { ViewData["Courrency"] = new SelectList(currency, "Id", "Name", model.CurrencyId = declarantContact.CurrencyId); } //Наличие сертификата GMP var repository = new ReadOnlyDictionaryRepository(); var booleans = repository.GetCertificateGMPCheck(); ViewData["IsGMPList"] = new SelectList(booleans, "CertificateGMPCheck", "NameRu", model.CertificateGMPCheck); var certType = safetyRepository.GetCertificateType(); if (model.CertificateTypeId == null) { ViewData["CertificateType"] = new SelectList(certType, "Id", "NameRu"); } else { ViewData["CertificateType"] = new SelectList(certType, "Id", "NameRu", model.CertificateTypeId); } //организационная форма var orgForm = safetyRepository.GetOrganizationForm(); if (declarant?.OrganizationFormId == null) { ViewData["OrganizationForm"] = new SelectList(orgForm, "Id", "Name"); } else { ViewData["OrganizationForm"] = new SelectList(orgForm, "Id", "Name", model.OrganizationFormId = declarant.OrganizationFormId); } model.StartDate = string.Format("{0:dd.MM.yyyy}", contract.StartDate); model.EndDate = string.Format("{0:dd.MM.yyyy}", contract.EndDate); model.NameKz = declarant?.NameKz ?? "нет данных"; model.NameRu = declarant?.NameRu ?? "нет данных"; model.NameEn = declarant?.NameEn ?? "нет данных"; model.ChiefLastName = declarantContact?.BossLastName ?? "нет данных"; model.ChiefFirstName = declarantContact?.BossFirstName ?? "нет данных"; model.ChiefMiddleName = declarantContact?.BossMiddleName ?? "нет данных"; model.ChiefPosition = declarantContact?.BossPosition ?? "нет данных"; model.AddressFact = declarantContact?.AddressFact ?? "нет данных"; model.AddressLegal = declarantContact?.AddressLegalRu ?? "нет данных"; model.Phone = declarantContact?.Phone ?? "нет данных"; model.Email = declarantContact?.Email ?? "нет данных"; model.BankBik = declarantContact?.BankBik ?? "нет данных"; model.BankIik = declarantContact?.BankIik ?? "нет данных"; model.BankName = declarantContact?.BankNameRu ?? "нет данных"; var resultProducts = new List <OBK_RS_Products>(); foreach (var product in products) { var prod = new OBK_RS_Products(); prod.Id = product.Id; prod.NameRu = product.NameRu; prod.NameKz = product.NameKz; prod.ProducerNameRu = product.ProducerNameRu; prod.ProducerNameKz = product.ProducerNameKz; prod.CountryNameRu = product.CountryNameRu; prod.CountryNameKZ = product.CountryNameKZ; prod.TnvedCode = product.TnvedCode; prod.KpvedCode = product.KpvedCode; prod.Price = product.Price; foreach (var productSeries in product.OBK_Procunts_Series) { var prodSeries = new OBK_Procunts_Series(); prodSeries.Id = productSeries.Id; prodSeries.Series = productSeries.Series; prodSeries.SeriesStartdate = productSeries.SeriesStartdate; prodSeries.SeriesEndDate = productSeries.SeriesEndDate; prodSeries.SeriesParty = productSeries.SeriesParty; prodSeries.SeriesShortNameRu = productSeries.sr_measures.short_name; prod.OBK_Procunts_Series.Add(prodSeries); } resultProducts.Add(prod); } model.ObkRsProductses = resultProducts; } else { var countries = safetyRepository.GetCounties(); ViewData["Counties"] = new SelectList(countries, "Id", "Name"); //Валюта var currency = safetyRepository.GetObkCurrencies(); ViewData["Courrency"] = new SelectList(currency, "Id", "Name"); var repository = new ReadOnlyDictionaryRepository(); //Наличие сертификата GMP var booleans = repository.GetCertificateGMPCheck(); ViewData["IsGMPList"] = new SelectList(booleans, "CertificateGMPCheck", "NameRu", model.CertificateGMPCheck); var certType = safetyRepository.GetCertificateType(); ViewData["CertificateType"] = new SelectList(certType, "Id", "NameRu"); //организационная форма var orgForm = safetyRepository.GetOrganizationForm(); ViewData["OrganizationForm"] = new SelectList(orgForm, "Id", "Name"); } }
/// <summary> /// сохранение заявления /// </summary> /// <param name="entity"></param> /// <param name="userId"></param> /// <returns></returns> public virtual OBK_AssessmentDeclaration SaveOrUpdate(OBK_AssessmentDeclaration entity, Guid?userId) { if (entity.Id == Guid.Empty) { try { entity.CreatedDate = DateTime.Now; AppContext.MarkAsAdded(entity); AppContext.Commit(true); return(entity); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } //var suspendedStage = AppContext.EXP_ExpertiseStage.FirstOrDefault(x => // !x.IsHistory // && x.DeclarationId == entity.Id // && x.IsSuspended //); //if (suspendedStage != null) //{ // LogHelper.Log.DebugFormat("Найден приостановленный этап {0}", suspendedStage.Id); // if (suspendedStage.SuspendedStartDate.HasValue) // { // suspendedStage.IsSuspended = false; // var suspendedDays = (DateTime.Now - suspendedStage.SuspendedStartDate.Value).TotalDays; // LogHelper.Log.DebugFormat("Всего дней приостановки {0}", suspendedDays); // if (suspendedStage.EndDate.HasValue) // { // suspendedStage.EndDate = suspendedStage.EndDate.Value.AddDays(suspendedDays); // } // else // { // LogHelper.Log.DebugFormat("У этапа {0} не указана дата завершения исполнения EndDate", suspendedStage.Id); // } // AppContext.Commit(true); // } // else // { // LogHelper.Log.DebugFormat("У этапа {0} почему-то не указана дата начала приостановки", suspendedStage.Id); // } //} //else //{ // LogHelper.Log.Debug("Заявление не содержит приостановленных этапов"); //} var attachedEntity = AppContext.Set <OBK_AssessmentDeclaration>().Find(entity.Id); AppContext.Entry(attachedEntity).CurrentValues.SetValues(entity); AppContext.Commit(true); //Отправка заявления на этап ЦОЗ if (entity.StatusId != CodeConstManager.STATUS_DRAFT_ID) { string resultDescription; var stageRepository = new AssessmentStageRepository(); if (!stageRepository.HasStage(entity.Id, CodeConstManager.STAGE_OBK_COZ)) { stageRepository.ToNextStage(entity.Id, null, new[] { CodeConstManager.STAGE_OBK_COZ }, out resultDescription); } } return(entity); }
public void SaveAssessmentDeclaration(OBK_AssessmentDeclaration declaration) { AppContext.OBK_AssessmentDeclaration.Add(declaration); AppContext.SaveChanges(); }
/// <summary> /// Перевод заявления на следующий этап /// </summary> /// <param name="declaration"></param> /// <param name="stageCode"></param> public bool ToNextStage(OBK_AssessmentDeclaration declaration, Guid?fromStageId, int[] nextStageIds, out string resultDescription) { resultDescription = null; string[] activeStageCodes = { OBK_Ref_StageStatus.New, OBK_Ref_StageStatus.InWork, OBK_Ref_StageStatus.InReWork }; //var declaration = AppContext.OBK_AssessmentDeclaration.FirstOrDefault(e => e.Id == declarationId); //if (declaration.EXP_DIC_Type.Code != EXP_DIC_Type.Registration) //{ // //return ToNextStage(declaration, fromStageId, nextStageIds, out resultDescription); //} var currentStage = fromStageId != null ? AppContext.OBK_AssessmentStage.FirstOrDefault(e => e.Id == fromStageId) : AppContext.OBK_AssessmentStage.FirstOrDefault( e => e.DeclarationId == declaration.Id && activeStageCodes.Contains(e.OBK_Ref_StageStatus.Code)); var stageStatusNew = GetStageStatusByCode(OBK_Ref_StageStatus.New); //закрываем предыдущий этап if (currentStage != null) //&& CanCloseStage(currentStage, nextStageIds) { currentStage.StageStatusId = GetStageStatusByCode(OBK_Ref_StageStatus.Completed).Id; currentStage.FactEndDate = DateTime.Now; } var isAnalitic = false; foreach (var nextStageId in nextStageIds) { //if (!CanSendToStep(declarationId, fromStageId, nextStageId, out resultDescription)) return false; //если имеется уже выполняющийся этап то продолжаем его дальше if (AppContext.OBK_AssessmentStage.Any(e => e.DeclarationId == declaration.Id && e.StageId == nextStageId && e.OBK_Ref_StageStatus.Code != OBK_Ref_StageStatus.Completed && !e.IsHistory)) { continue; } //todo переделать дату окончания этапа var daysOnStage = 0;//GetExpStageDaysOnExecution(declaration.TypeId, nextStageId); var startDate = DateTime.Now; var newStage = new OBK_AssessmentStage() { Id = Guid.NewGuid(), DeclarationId = declaration.Id, StageId = nextStageId, ParentStageId = currentStage != null ? (Guid?)currentStage.Id : null, StageStatusId = stageStatusNew.Id, StartDate = startDate, EndDate = daysOnStage != null ? (DateTime?)startDate.AddDays(daysOnStage) : null }; var newStageExecutor = new OBK_AssessmentStageExecutors { AssessmentStageId = newStage.Id, ExecutorId = GetExecutorByDicStageId(nextStageId, declaration.OBK_Contract.ExpertOrganization, declaration.TypeId).Id, ExecutorType = CodeConstManager.OBK_CONTRACT_STAGE_EXECUTOR_TYPE_ASSIGNING }; newStage.OBK_AssessmentStageExecutors.Add(newStageExecutor); var ex = AppContext.OBK_AssessmentDeclaration.Where(r => r.ContractId == newStage.DeclarationId).FirstOrDefault(); new SafetyAssessmentRepository().AddHistory(declaration.Id, OBK_Ref_StageStatus.New, newStageExecutor.ExecutorId); AppContext.OBK_AssessmentStage.Add(newStage); } AppContext.SaveChanges(); return(true); }