コード例 #1
0
        public int AddEvent(int dossierId, string description, int responsible, DateTime deadline, DateTime?completionDate)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Planning planning = new Planning();
                planning.DossierId      = dossierId;
                planning.Description    = description;
                planning.Responsible    = responsible;
                planning.Deadline       = deadline;
                planning.CompletionDate = completionDate;
                planning.Created        = DateTime.Now;

                /*  FluentValidation.Results.ValidationResult validationResult = new DossierValidator().Validate(dossier);
                 *
                 *  if (validationResult.IsValid)
                 *  {*/
                dossierContext.Planning.Add(planning);

                result = dossierContext.SaveChanges();

                /*     }
                 *   else
                 *   {
                 *       DossierValidator.DisplayErrorMessage(validationResult);
                 *   }*/
            }

            return(result);
        }
コード例 #2
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);
        }
コード例 #3
0
        public int RemoveEvent(int id)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Planning planning = dossierContext.Planning.Where(c => c.Id == id).First();
                dossierContext.Planning.Remove(planning);
                result = dossierContext.SaveChanges();
            }

            return(result);
        }
コード例 #4
0
        public int DeleteDossier(int id, byte[] rowVersion)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Dossier dossier = dossierContext.Dossiers.Where(c => c.Id == id).First();
                dossierContext.Dossiers.Remove(dossier);
                result = dossierContext.SaveChanges();

                this.RefreshDossierList(this.overviewForm.IsShowingArchivedItems());
            }

            return(result);
        }
コード例 #5
0
        public int Delete(int id)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Persoon persoon = dossierContext.Personen.Where(c => c.Id == id).First();
                dossierContext.Personen.Remove(persoon);
                result = dossierContext.SaveChanges();

                this.GetPersonList();

                this.personViewForm.SetPersonList(this.personList, "name", "Id");
            }

            return(result);
        }
コード例 #6
0
        public int Save(int id, string name, string email, string organisation, string departement, byte[] rowVersion)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Persoon persoon = dossierContext.Personen.SingleOrDefault(c => c.Id == id);

                if (persoon == null)
                {
                    return(this.SaveNew(out id, name, email, organisation, departement));
                }
                else
                {
                    if (Database.DossierContext.ByteArrayCompare(rowVersion, persoon.RowVersion))
                    {
                        persoon.Naam        = name;
                        persoon.Email       = email;
                        persoon.Organisatie = organisation;
                        persoon.Departement = departement;

                        FluentValidation.Results.ValidationResult validationResult = new Model.PersoonValidator().Validate(persoon);

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

                        this.GetPersonList();

                        this.personViewForm.SetPersonList(this.personList, "name", "Id");
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Persoon werd gewijzigd door een andere gebruiker.", "Persoon gewijzigd", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }
                }
            }

            return(result);
        }
コード例 #7
0
        public int SaveNew(out int id, string name, string email, string organisation, string departement)
        {
            int result = 0;

            id = -1;

            Persoon persoon = new Persoon();

            persoon.Naam        = name;
            persoon.Email       = email;
            persoon.Organisatie = organisation;
            persoon.Departement = departement;

            FluentValidation.Results.ValidationResult validationResult = new Model.PersoonValidator().Validate(persoon);

            if (validationResult.IsValid)
            {
                using (Database.DossierContext dossierContext = new Database.DossierContext())
                {
                    dossierContext.Personen.Add(persoon);
                    result = dossierContext.SaveChanges();

                    this.GetPersonList();

                    this.personViewForm.SetPersonList(this.personList, "name", "Id");
                    if (result > 0)
                    {
                        id = persoon.Id;
                    }
                    else
                    {
                        id = -1;
                    }
                }
            }
            else
            {
                Model.PersoonValidator.DisplayErrorMessage(validationResult);
            }

            return(result);
        }
コード例 #8
0
        public int UpdateEvent(int id, int dossierId, string description, int responsible, DateTime deadline, DateTime?completionDate)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Planning planning = dossierContext.Planning.Where(c => c.Id == id).First();
                if (planning != null)
                {
                    planning.DossierId      = dossierId;
                    planning.Description    = description;
                    planning.Responsible    = responsible;
                    planning.Deadline       = deadline;
                    planning.CompletionDate = completionDate;
                    result = dossierContext.SaveChanges();
                }
            }

            return(result);
        }
コード例 #9
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);
        }
コード例 #10
0
        public int PersistLinkedPersonList(List <Tuple <string, int> > linkedPersons)
        {
            List <int> personsToRemove = new List <int>();

            foreach (Persoon stored_p in this.personList)
            {
                bool found = false;
                foreach (Tuple <string, int> new_p in linkedPersons)
                {
                    if (stored_p.Id == new_p.Item2)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    personsToRemove.Add(stored_p.Id);
                }
            }

            foreach (Tuple <string, int> new_p in linkedPersons)
            {
                bool found = false;
                foreach (Persoon stored_p in this.personList)
                {
                    if (stored_p.Id == new_p.Item2)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    this.personsToAdd.Add(new_p.Item2);
                }
            }

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                foreach (int p in personsToRemove)
                {
                    DossierPersoon dp = dossierContext.DossierPersoon.SingleOrDefault(c => c.PersoonId == p && c.DossierId == this.dossierId);
                    if (dp != null)
                    {
                        dossierContext.DossierPersoon.Remove(dp);
                    }
                }

                foreach (int p in this.personsToAdd)
                {
                    if (this.dossierId != null)
                    {
                        DossierPersoon dp = new DossierPersoon();

                        dp.DossierId = (int)this.dossierId;
                        dp.PersoonId = p;

                        dossierContext.DossierPersoon.Add(dp);
                    }
                }

                this.modifiedCount = dossierContext.SaveChanges();
            }

            return(this.modifiedCount);
        }