Esempio n. 1
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);
        }
Esempio n. 2
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);
        }