Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
 public void ShowWithID(int id)
 {
     using (Database.DossierContext dossierContext = new Database.DossierContext())
     {
         Persoon persoon = dossierContext.Personen.SingleOrDefault(c => c.Id == id);
         if (persoon != null)
         {
             this.personViewForm.SetPerson(persoon.Id, persoon.Naam, persoon.Email, persoon.Organisatie, persoon.Departement, persoon.RowVersion);
         }
     }
 }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void RefreshDossierList(bool showArchived)
        {
            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                if (!showArchived)
                {
                    this.dossierList = dossierContext.Dossiers.Where(c => c.IsGearchiveerd == false).OrderBy(s => s.DossierNummer).ToList();
                }
                else
                {
                    this.dossierList = dossierContext.Dossiers.OrderBy(s => s.DossierNummer).ToList();
                }

                this.overviewForm.SetDossierList(this.dossierList, "Name", "Id");
            }
        }
Esempio n. 7
0
        // private List<Planning> planningList;
        public List <Planning> GetEventList(int?dossierId)
        {
            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                if (dossierId == null)
                {
                    return(dossierContext.Planning.ToList());
                }
                else
                {
                    return(dossierContext.Planning.Where(c => c.DossierId == dossierId).OrderBy(s => s.Deadline).ToList());

                    // return (from t3 in dossierContext.Planning where t3.Id == dossierId select t3).ToList();
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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. 10
0
 private void GetPersonList()
 {
     using (Database.DossierContext dossierContext = new Database.DossierContext())
     {
         if (this.dossierId == null)
         {
             this.personList = dossierContext.Personen.ToList();
         }
         else
         {
             this.personList = (from t3 in dossierContext.DossierPersoon
                                where t3.DossierId == this.dossierId
                                from t2 in dossierContext.Personen
                                where t2.Id == t3.PersoonId
                                select t2).ToList();
         }
     }
 }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public void ShowWithID(int id)
        {
            Dossier dossier = null;

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

            if (dossier != null)
            {
                Controller.PersonController personController = new Controller.PersonController(id);

                List <Tuple <string, int> > contactpersonen = personController.GetNameTuples();
                string procedure          = Automat.Rules.DossierRules.GetProcedureName(dossier.DossierProcedure);
                string type               = Rules.DossierRules.GetProcedureTypeName(dossier.DossierType, true);
                string procuringEnityName = Rules.DossierRules.GetProcuringEntityName(dossier.ProcuringEnity);
                string contractTypeName   = Rules.DossierRules.GetContractTypeName(dossier.TypeOfContract);

                Controller.PlanningController           planningController = new PlanningController(null);
                List <Tripple <string, DateTime, int> > events             = planningController.GetEvents(id);

                this.DossierId = id;

                this.overviewForm.Setdossier(
                    dossier.Id,
                    dossier.DossierNummer,
                    dossier.DossierTitel,
                    dossier.DossierStandvanzaken,
                    dossier.IsGearchiveerd,
                    contactpersonen,
                    dossier.DossierLinkToFiles,
                    procedure,
                    type,
                    dossier.IsEuropeanPublished,
                    procuringEnityName,
                    contractTypeName,
                    events,
                    dossier.RowVersion);
            }
        }
Esempio n. 14
0
        public int GetEvent(int id, out int dossierId, out string description, out int responsible, out DateTime deadline, out DateTime?completionDate, out DateTime creationDate)
        {
            int result = 0;

            using (Database.DossierContext dossierContext = new Database.DossierContext())
            {
                Planning planning = dossierContext.Planning.Where(c => c.Id == id).First();
                if (planning != null)
                {
                    result = 1;
                }

                dossierId      = planning.DossierId;
                description    = planning.Description;
                responsible    = planning.Responsible;
                deadline       = planning.Deadline;
                completionDate = planning.CompletionDate;
                creationDate   = planning.Created;
            }

            return(result);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }