Ejemplo n.º 1
0
        public int SaveNewDossier(out int id, string nummer, string titel, string stavaza)
        {
            int result = 0;

            id = -1;
            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Dossier dossier = new Dossier();
                dossier.DossierNummer        = nummer;
                dossier.DossierTitel         = titel;
                dossier.DossierStandvanzaken = stavaza;
                dossier.IsGearchiveerd       = false;
                dossier.DossierLinkToFiles   = Automat.Rules.DossierRules.GetFileLocation(nummer);

                FluentValidation.Results.ValidationResult validationResult = new DossierValidator().Validate(dossier);

                if (validationResult.IsValid)
                {
                    dossierContext.Dossiers.Add(dossier);
                    result = dossierContext.SaveChanges();

                    this.RefreshDossierList(this.overviewForm.IsShowingArchivedItems());
                    if (result > 0)
                    {
                        id = dossier.Id;
                    }
                }
                else
                {
                    DossierValidator.DisplayErrorMessage(validationResult);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public int SaveDossier(
            int id,
            string nummer,
            string titel,
            string stavaza,
            bool isArchived,
            string linkTofiles,
            string procedure,
            string type,
            bool isEuropeanPublished,
            string procuringEnityName,
            string contractTypeName,
            byte[] rowVersion)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Dossier dossier = dossierContext.Dossiers.SingleOrDefault(c => c.Id == id);

                // the dossier is delete by another user?
                if (dossier == null)
                {
                    this.overviewForm.SetStatusText("Entry was deleted by another user.");
                    return(this.SaveNewDossier(out id, nummer, titel, stavaza));
                }
                else
                {
                    if (Database.DossierContext.ByteArrayCompare(rowVersion, dossier.RowVersion))
                    {
                        dossier.DossierNummer        = nummer;
                        dossier.DossierTitel         = titel;
                        dossier.DossierStandvanzaken = stavaza;
                        dossier.IsGearchiveerd       = isArchived;
                        if (linkTofiles != string.Empty)
                        {
                            dossier.DossierLinkToFiles = linkTofiles;
                        }
                        else
                        {
                            dossier.DossierLinkToFiles = Automat.Rules.DossierRules.GetFileLocation(nummer);
                        }

                        dossier.DossierProcedure    = Automat.Rules.DossierRules.GetProcedureID(procedure);
                        dossier.DossierType         = Rules.DossierRules.GetProcedureTypeID(type, true);
                        dossier.IsEuropeanPublished = isEuropeanPublished;
                        dossier.ProcuringEnity      = Rules.DossierRules.GetProcuringEntityID(procuringEnityName);
                        dossier.TypeOfContract      = Rules.DossierRules.GetContractTypeID(contractTypeName);

                        // Do validation of Dossier object:
                        FluentValidation.Results.ValidationResult validationResult = new DossierValidator().Validate(dossier);

                        if (validationResult.IsValid)
                        {
                            result = dossierContext.SaveChanges();
                        }
                        else
                        {
                            DossierValidator.DisplayErrorMessage(validationResult);
                        }

                        this.RefreshDossierList(this.overviewForm.IsShowingArchivedItems());
                    }
                    else
                    {
                        this.overviewForm.SetStatusText("Entry was modified by another user.");
                    }
                }
            }

            return(result);
        }