Example #1
0
        public ActionResult StatementSave(EmpStatementViewModel vm)
        {
            var statement = _ctx.EMP_Statement.FirstOrDefault(x => x.Id == vm.Id);

            if (statement == null)
            {
                statement = new EMP_Statement {
                    Id = Guid.NewGuid()
                };
                _ctx.EMP_Statement.Add(statement);
            }

            statement.RegistrationKindValue         = vm.RegistrationKindValue;
            statement.RegistrationCertificateNumber = vm.RegistrationCertificateNumber;
            statement.NormativeDocumentNumber       = vm.NormativeDocumentNumber;
            if (vm.RegistrationDate != null)
            {
                statement.RegistrationDate = vm.RegistrationDate;
            }
            if (vm.ExpirationDate != null)
            {
                statement.ExpirationDate = vm.ExpirationDate;
            }
            statement.ContractId            = vm.ContractId;
            statement.RegistrationTypeValue = vm.RegistrationTypeValue;
            statement.LetterNumber          = vm.LetterNumber;
            if (vm.LetterDate != null)
            {
                statement.LetterDate = vm.LetterDate;
            }
            statement.IsMt = vm.IsMt;
            statement.MedicalDeviceNameKz            = vm.MedicalDeviceNameKz;
            statement.MedicalDeviceNameRu            = vm.MedicalDeviceNameRu;
            statement.NomenclatureCode               = vm.NomenclatureCode;
            statement.NmirkId                        = vm.NmirkId;
            statement.NomenclatureNameKz             = vm.NomenclatureNameKz;
            statement.NomenclatureNameRu             = vm.NomenclatureNameRu;
            statement.NomenclatureDescriptionKz      = vm.NomenclatureDescriptionKz;
            statement.NomenclatureDescriptionRu      = vm.NomenclatureDescriptionRu;
            statement.ApplicationAreaKz              = string.Join(",", vm.ApplicationAreaKz);
            statement.ApplicationAreaRu              = string.Join(",", vm.ApplicationAreaRu);
            statement.PurposeKz                      = vm.PurposeKz;
            statement.PurposeRu                      = vm.PurposeRu;
            statement.IsClosedSystem                 = vm.IsClosedSystem;
            statement.RegistrationDossierPageNumber  = vm.RegistrationDossierPageNumber;
            statement.ShortTechnicalCharacteristicKz = vm.ShortTechnicalCharacteristicKz;
            statement.ShortTechnicalCharacteristicRu = vm.ShortTechnicalCharacteristicRu;
            statement.ClassOfPotentialRisk           = vm.ClassOfPotentialRisk;
            statement.IsBalk = vm.IsBalk;
            statement.IsMeasurementDevice     = vm.IsMeasurementDevice;
            statement.IsForInvitroDiagnostics = vm.IsForInvitroDiagnostics;
            statement.IsSterile = vm.IsSterile;
            statement.IsMedicalProductPresence = vm.IsMedicalProductPresence;
            statement.WithouAe              = vm.WithouAe;
            statement.TransportConditions   = vm.TransportConditions;
            statement.StorageConditions     = vm.StorageConditions;
            statement.Production            = vm.Production;
            statement.IsComplectation       = vm.IsComplectation;
            statement.ManufacturerType      = vm.ManufacturerType;
            statement.ManufacturerNameRu    = vm.ManufacturerNameRu;
            statement.AllowedDocumentNumber = vm.AllowedDocumentNumber;
            statement.BossLastName          = vm.BossLastName;
            statement.BossPosition          = vm.BossPosition;
            statement.OrganizationForm      = vm.OrganizationForm;
            statement.ManufacturerNameKz    = vm.ManufacturerNameKz;
            if (vm.DateOfIssue != null)
            {
                statement.DateOfIssue = vm.DateOfIssue;
            }
            statement.BossFirstName      = vm.BossFirstName;
            statement.Phone              = vm.Phone;
            statement.Country            = vm.Country;
            statement.ManufacturerNameEn = vm.ManufacturerNameEn;
            if (vm.ManufacturerExpirationDate != null)
            {
                statement.ManufacturerExpirationDate = vm.ManufacturerExpirationDate;
            }
            statement.BossMiddleName            = vm.BossMiddleName;
            statement.Email                     = vm.Email;
            statement.ContactPersonInitials     = vm.ContactPersonInitials;
            statement.ContactPersonLegalAddress = vm.ContactPersonLegalAddress;
            statement.ContactPersonPosition     = vm.ContactPersonPosition;
            statement.ContactPersonFactAddress  = vm.ContactPersonFactAddress;
            statement.Agreement                 = vm.Agreement;
            statement.IsAgreed                  = vm.IsAgreed;

            if (vm.ChangeData != null)
            {
                var changes = _ctx.EMP_StatementChange.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var changeVm in vm.ChangeData)
                {
                    var change = changes.FirstOrDefault(x => x.Id == changeVm.Id);
                    if (change == null)
                    {
                        change = new EMP_StatementChange {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementChange.Add(change);
                    }
                    change.Name         = changeVm.Name;
                    change.Type         = changeVm.Type;
                    change.BeforeChange = changeVm.BeforeChange;
                    change.AfterChange  = changeVm.AfterChange;
                }
            }

            if (vm.StorageLifeData != null)
            {
                var storageLifes = _ctx.EMP_StatementStorageLife.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var storageLifeVm in vm.StorageLifeData)
                {
                    var storageLife = storageLifes.FirstOrDefault(x => x.Id == storageLifeVm.Id);
                    if (storageLife == null)
                    {
                        storageLife = new EMP_StatementStorageLife {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementStorageLife.Add(storageLife);
                    }
                    storageLife.Kind = storageLifeVm.Kind;
                    if (storageLifeVm.ExpirationDate != null)
                    {
                        storageLife.ExpirationDate = storageLifeVm.ExpirationDate;
                    }
                    storageLife.Measure        = storageLifeVm.Measure;
                    storageLife.IsIndefinitely = storageLifeVm.IsIndefinitely;
                }
            }

            if (vm.CountryRegistrationData != null)
            {
                var countryRegistrations = _ctx.EMP_StatementCountryRegistration.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var countryRegistrationVm in vm.CountryRegistrationData)
                {
                    var countryRegistration = countryRegistrations.FirstOrDefault(x => x.Id == countryRegistrationVm.Id);
                    if (countryRegistration == null)
                    {
                        countryRegistration = new EMP_StatementCountryRegistration {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementCountryRegistration.Add(countryRegistration);
                    }
                    countryRegistration.Country            = countryRegistrationVm.Country;
                    countryRegistration.RegistrationNumber = countryRegistrationVm.RegistrationNumber;
                    if (countryRegistrationVm.StartDate != null)
                    {
                        countryRegistration.StartDate = countryRegistrationVm.StartDate;
                    }
                    if (countryRegistrationVm.ExpirationDate != null)
                    {
                        countryRegistration.ExpirationDate = countryRegistrationVm.ExpirationDate;
                    }
                    countryRegistration.IsIndefinitely = countryRegistrationVm.IsIndefinitely;
                }
            }

            if (vm.MedicalDeviceComplectationData != null)
            {
                var complectations = _ctx.EMP_StatementMedicalDeviceComplectation.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var complectationVm in vm.MedicalDeviceComplectationData)
                {
                    var complectation = complectations.FirstOrDefault(x => x.Id == complectationVm.Id);
                    if (complectation == null)
                    {
                        complectation = new EMP_StatementMedicalDeviceComplectation {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementMedicalDeviceComplectation.Add(complectation);
                    }
                    complectation.Type         = complectationVm.Type;
                    complectation.Name         = complectationVm.Name;
                    complectation.Identifier   = complectationVm.Identifier;
                    complectation.Model        = complectationVm.Model;
                    complectation.Manufacturer = complectationVm.Manufacturer;
                    complectation.Country      = complectationVm.Country;
                }
            }

            if (vm.MedicalDevicePackageData != null)
            {
                var packages = _ctx.EMP_StatementMedicalDevicePackage.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var packageVm in vm.MedicalDevicePackageData)
                {
                    var package = packages.FirstOrDefault(x => x.Id == packageVm.Id);
                    if (package == null)
                    {
                        package = new EMP_StatementMedicalDevicePackage {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementMedicalDevicePackage.Add(package);
                    }
                    package.Kind        = packageVm.Kind;
                    package.Name        = packageVm.Name;
                    package.VolumeValue = packageVm.VolumeValue;
                    package.VolumeUnit  = packageVm.VolumeUnit;
                    package.Count       = packageVm.Count;
                    package.Description = packageVm.Description;
                }
            }

            if (vm.Samples != null)
            {
                statement.EMP_StatementSamples = vm.Samples.Select(s =>
                {
                    var res = new EMP_StatementSamples
                    {
                        Addition       = s.Addition,
                        Conditions     = s.Conditions,
                        Count          = s.Count,
                        CreateDate     = s.CreateDate,
                        ExpirationDate = s.ExpirationDate,
                        Name           = s.Name,
                        SampleType     = s.SampleType,
                        SeriesPart     = s.SeriesPart,
                        StatementId    = vm.Id,
                        Storage        = s.Storage,
                        Unit           = s.Unit
                    };
                    if (s.Id != 0)
                    {
                        res.Id = s.Id;
                    }
                    return(res);
                }).ToList();
            }

            _ctx.SaveChanges();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public ActionResult StatementSave(EmpEaesStatementViewModel vm)
        {
            var statement = _ctx.EMP_EAESStatement.FirstOrDefault(x => x.Id == vm.Id);

            if (statement == null)
            {
                statement = new EMP_EAESStatement {
                    Id = Guid.NewGuid()
                };
                _ctx.EMP_EAESStatement.Add(statement);
            }

            statement.RegistrationKindValue         = vm.RegistrationKindValue;
            statement.RegistrationCertificateNumber = vm.RegistrationCertificateNumber;
            statement.NormativeDocumentNumber       = vm.NormativeDocumentNumber;
            if (vm.RegistrationDate != null)
            {
                statement.RegistrationDate = vm.RegistrationDate;
            }
            if (vm.ExpirationDate != null)
            {
                statement.ExpirationDate = vm.ExpirationDate;
            }
            statement.ContractId   = vm.ContractId;
            statement.LetterNumber = vm.LetterNumber;
            if (vm.LetterDate != null)
            {
                statement.LetterDate = vm.LetterDate;
            }
            statement.IsMt = vm.IsMt;
            statement.MedicalDeviceNameKz            = vm.MedicalDeviceNameKz;
            statement.MedicalDeviceNameRu            = vm.MedicalDeviceNameRu;
            statement.NomenclatureCode               = vm.NomenclatureCode;
            statement.NmirkId                        = vm.NmirkId;
            statement.NomenclatureNameKz             = vm.NomenclatureNameKz;
            statement.NomenclatureNameRu             = vm.NomenclatureNameRu;
            statement.NomenclatureDescriptionKz      = vm.NomenclatureDescriptionKz;
            statement.NomenclatureDescriptionRu      = vm.NomenclatureDescriptionRu;
            statement.ApplicationAreaKz              = string.Join(",", vm.ApplicationAreaKz);
            statement.ApplicationAreaRu              = string.Join(",", vm.ApplicationAreaRu);
            statement.PurposeKz                      = vm.PurposeKz;
            statement.PurposeRu                      = vm.PurposeRu;
            statement.IsClosedSystem                 = vm.IsClosedSystem;
            statement.RegistrationDossierPageNumber  = vm.RegistrationDossierPageNumber;
            statement.ShortTechnicalCharacteristicKz = vm.ShortTechnicalCharacteristicKz;
            statement.ShortTechnicalCharacteristicRu = vm.ShortTechnicalCharacteristicRu;
            statement.ClassOfPotentialRisk           = vm.ClassOfPotentialRisk;
            statement.IsBalk = vm.IsBalk;
            statement.IsMeasurementDevice     = vm.IsMeasurementDevice;
            statement.IsForInvitroDiagnostics = vm.IsForInvitroDiagnostics;
            statement.IsSterile = vm.IsSterile;
            statement.IsMedicalProductPresence = vm.IsMedicalProductPresence;
            statement.WithouAe              = vm.WithouAe;
            statement.TransportConditions   = vm.TransportConditions;
            statement.StorageConditions     = vm.StorageConditions;
            statement.Production            = vm.Production;
            statement.IsComplectation       = vm.IsComplectation;
            statement.ManufacturerType      = vm.ManufacturerType;
            statement.ManufacturerNameRu    = vm.ManufacturerNameRu;
            statement.AllowedDocumentNumber = vm.AllowedDocumentNumber;
            statement.BossLastName          = vm.BossLastName;
            statement.BossPosition          = vm.BossPosition;
            statement.OrganizationForm      = vm.OrganizationForm;
            statement.ManufacturerNameKz    = vm.ManufacturerNameKz;
            if (vm.DateOfIssue != null)
            {
                statement.DateOfIssue = vm.DateOfIssue;
            }
            statement.BossFirstName      = vm.BossFirstName;
            statement.Phone              = vm.Phone;
            statement.Country            = vm.Country;
            statement.ManufacturerNameEn = vm.ManufacturerNameEn;
            if (vm.ManufacturerExpirationDate != null)
            {
                statement.ManufacturerExpirationDate = vm.ManufacturerExpirationDate;
            }
            statement.BossMiddleName            = vm.BossMiddleName;
            statement.Email                     = vm.Email;
            statement.ContactPersonInitials     = vm.ContactPersonInitials;
            statement.ContactPersonLegalAddress = vm.ContactPersonLegalAddress;
            statement.ContactPersonPosition     = vm.ContactPersonPosition;
            statement.ContactPersonFactAddress  = vm.ContactPersonFactAddress;
            statement.Agreement                 = vm.Agreement;
            statement.IsAgreed                  = vm.IsAgreed;
            statement.RefCountry                = vm.RefCountry;
            statement.ConCountry                = vm.ConCountry;
            statement.GarantExpDate             = vm.GarantExpDate;
            statement.GarantNoExp               = vm.GarantNoExp;
            statement.GarantUnit                = vm.GarantUnit;

            statement.PlaceType   = vm.PlaceType;
            statement.PlaceNameRu = vm.PlaceNameRu;
            statement.PlaceAllowedDocumentNumber = vm.PlaceAllowedDocumentNumber;
            statement.PlaceBossLastName          = vm.PlaceBossLastName;
            statement.PlaceBossPosition          = vm.PlaceBossPosition;
            statement.PlaceOrganizationForm      = vm.PlaceOrganizationForm;
            statement.PlaceNameKz                      = vm.PlaceNameKz;
            statement.PlaceDateOfIssue                 = vm.PlaceDateOfIssue;
            statement.PlaceBossFirstName               = vm.PlaceBossFirstName;
            statement.PlacePhone                       = vm.PlacePhone;
            statement.PlaceCountry                     = vm.PlaceCountry;
            statement.PlaceNameEn                      = vm.PlaceNameEn;
            statement.PlaceExpirationDate              = vm.PlaceExpirationDate;
            statement.PlaceBossMiddleName              = vm.PlaceBossMiddleName;
            statement.PlaceEmail                       = vm.PlaceEmail;
            statement.PlaceContactPersonInitials       = vm.PlaceContactPersonInitials;
            statement.PlaceContactPersonPosition       = vm.PlaceContactPersonPosition;
            statement.PlaceContactPersonFactAddress    = vm.PlaceContactPersonFactAddress;
            statement.ShowerType                       = vm.ShowerType;
            statement.ShowerNameRu                     = vm.ShowerNameRu;
            statement.ShowerPAllowedDocumentNumber     = vm.ShowerAllowedDocumentNumber;
            statement.ShowerBossLastName               = vm.ShowerBossLastName;
            statement.ShowerBossPosition               = vm.ShowerBossPosition;
            statement.ShowerOrganizationForm           = vm.ShowerOrganizationForm;
            statement.ShowerNameKz                     = vm.ShowerNameKz;
            statement.ShowerDateOfIssue                = vm.ShowerDateOfIssue;
            statement.ShowerBossFirstName              = vm.ShowerBossFirstName;
            statement.ShowerPhone                      = vm.ShowerPhone;
            statement.ShowerCountry                    = vm.ShowerCountry;
            statement.ShowerNameEn                     = vm.ShowerNameEn;
            statement.ShowerExpirationDate             = vm.ShowerExpirationDate;
            statement.ShowerBossMiddleName             = vm.ShowerBossMiddleName;
            statement.ShowerEmail                      = vm.ShowerEmail;
            statement.ShowerContactPersonInitials      = vm.ShowerContactPersonInitials;
            statement.ShowerContactPersonPosition      = vm.ShowerContactPersonPosition;
            statement.ShowerContactPersonFactAddress   = vm.ShowerContactPersonFactAddress;
            statement.ShowerContactPersonActualAddress = vm.ShowerContactPersonActualAddress;

            if (vm.ChangeData != null)
            {
                var changes = _ctx.EMP_StatementChange.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var changeVm in vm.ChangeData)
                {
                    var change = changes.FirstOrDefault(x => x.Id == changeVm.Id);
                    if (change == null)
                    {
                        change = new EMP_StatementChange {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementChange.Add(change);
                    }
                    change.Name         = changeVm.Name;
                    change.Type         = changeVm.Type;
                    change.BeforeChange = changeVm.BeforeChange;
                    change.AfterChange  = changeVm.AfterChange;
                }
            }

            if (vm.StorageLifeData != null)
            {
                var storageLifes = _ctx.EMP_StatementStorageLife.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var storageLifeVm in vm.StorageLifeData)
                {
                    var storageLife = storageLifes.FirstOrDefault(x => x.Id == storageLifeVm.Id);
                    if (storageLife == null)
                    {
                        storageLife = new EMP_StatementStorageLife {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementStorageLife.Add(storageLife);
                    }
                    storageLife.Kind = storageLifeVm.Kind;
                    if (storageLifeVm.ExpirationDate != null)
                    {
                        storageLife.ExpirationDate = storageLifeVm.ExpirationDate;
                    }
                    storageLife.Measure        = storageLifeVm.Measure;
                    storageLife.IsIndefinitely = storageLifeVm.IsIndefinitely;
                }
            }

            if (vm.CountryRegistrationData != null)
            {
                var countryRegistrations = _ctx.EMP_StatementCountryRegistration.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var countryRegistrationVm in vm.CountryRegistrationData)
                {
                    var countryRegistration = countryRegistrations.FirstOrDefault(x => x.Id == countryRegistrationVm.Id);
                    if (countryRegistration == null)
                    {
                        countryRegistration = new EMP_StatementCountryRegistration {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementCountryRegistration.Add(countryRegistration);
                    }
                    countryRegistration.Country            = countryRegistrationVm.Country;
                    countryRegistration.RegistrationNumber = countryRegistrationVm.RegistrationNumber;
                    if (countryRegistrationVm.StartDate != null)
                    {
                        countryRegistration.StartDate = countryRegistrationVm.StartDate;
                    }
                    if (countryRegistrationVm.ExpirationDate != null)
                    {
                        countryRegistration.ExpirationDate = countryRegistrationVm.ExpirationDate;
                    }
                    countryRegistration.IsIndefinitely = countryRegistrationVm.IsIndefinitely;
                }
            }

            if (vm.MedicalDeviceComplectationData != null)
            {
                var complectations = _ctx.EMP_StatementMedicalDeviceComplectation.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var complectationVm in vm.MedicalDeviceComplectationData)
                {
                    var complectation = complectations.FirstOrDefault(x => x.Id == complectationVm.Id);
                    if (complectation == null)
                    {
                        complectation = new EMP_StatementMedicalDeviceComplectation {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementMedicalDeviceComplectation.Add(complectation);
                    }
                    complectation.Type         = complectationVm.Type;
                    complectation.Name         = complectationVm.Name;
                    complectation.Identifier   = complectationVm.Identifier;
                    complectation.Model        = complectationVm.Model;
                    complectation.Manufacturer = complectationVm.Manufacturer;
                    complectation.Country      = complectationVm.Country;
                }
            }

            if (vm.MedicalDevicePackageData != null)
            {
                var packages = _ctx.EMP_StatementMedicalDevicePackage.Where(x => x.StatementId == statement.Id).ToList();
                foreach (var packageVm in vm.MedicalDevicePackageData)
                {
                    var package = packages.FirstOrDefault(x => x.Id == packageVm.Id);
                    if (package == null)
                    {
                        package = new EMP_StatementMedicalDevicePackage {
                            Id = Guid.NewGuid(), StatementId = statement.Id
                        };
                        _ctx.EMP_StatementMedicalDevicePackage.Add(package);
                    }
                    package.Kind        = packageVm.Kind;
                    package.Name        = packageVm.Name;
                    package.VolumeValue = packageVm.VolumeValue;
                    package.VolumeUnit  = packageVm.VolumeUnit;
                    package.Count       = packageVm.Count;
                    package.Description = packageVm.Description;
                }
            }

            //if (vm.Samples != null)
            //{
            //    statement.EMP_StatementSamples = vm.Samples.Select(s =>
            //    {
            //        var res = new EMP_StatementSamples
            //        {
            //            Addition = s.Addition,
            //            Conditions = s.Conditions,
            //            Count = s.Count,
            //            CreateDate = s.CreateDate,
            //            ExpirationDate = s.ExpirationDate,
            //            Name = s.Name,
            //            SampleType = s.SampleType,
            //            SeriesPart = s.SeriesPart,
            //            StatementId = vm.Id,
            //            Storage = s.Storage,
            //            Unit = s.Unit
            //        };
            //        if (s.Id != 0) res.Id = s.Id;
            //        return res;
            //    }).ToList();
            //}

            if (vm.RegCountries != null && vm.RegCountries.Count() > 0)
            {
                vm.RegCountries.ToList().ForEach(rc =>
                {
                    var current = _ctx.EMP_EAESStatementRegCountry.FirstOrDefault(c => c.Id == rc.Id);
                    if (current != null)
                    {
                        current.IsIndefinitely = rc.IsIndefinitely;
                        current.RegNumber      = rc.RegNumber;
                        current.StatementId    = statement.Id;
                        current.Country        = rc.Country;
                        current.DateOfIssue    = rc.DateOfIssue ?? current.DateOfIssue;
                        current.ExpDate        = rc.ExpDate ?? current.ExpDate;
                    }
                    else
                    {
                        var nc = new EMP_EAESStatementRegCountry
                        {
                            Country        = rc.Country,
                            DateOfIssue    = rc.DateOfIssue,
                            ExpDate        = rc.ExpDate,
                            IsIndefinitely = rc.IsIndefinitely,
                            RegNumber      = rc.RegNumber,
                            StatementId    = statement.Id
                        };
                        if (nc.DateOfIssue == null)
                        {
                            Console.Write("cheat");
                        }
                        _ctx.EMP_EAESStatementRegCountry.Add(nc);
                    }
                });
            }

            _ctx.SaveChanges();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }