Beispiel #1
0
        public async Task <ActionResult <ExpenseLine> > PostExpenseLine(ExpenseLine expenseLine)
        {
            _context.ExpenseLine.Add(expenseLine);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetExpenseLine", new { id = expenseLine.Id }, expenseLine));
        }
Beispiel #2
0
        public async Task <bool> StoreNewExpenseLineAsync(int ExpenseId, ExpenseLine ExpenseLine)
        {
            ExpenseLine.ExpenseId = ExpenseId;

            _context.ExpenseLines.Add(ExpenseLine);
            return((await _context.SaveChangesAsync()) > 0);
        }
Beispiel #3
0
        /// <summary>
        /// This function actually performs the validation.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        protected override IEnumerable <ValidationResult> Validate(AddUpdateExpenseLineInfo command)
        {
            List <ValidationResult> validationResults = new List <ValidationResult>();

            ExpenseLine existingExpenseLine = expensesDb.ExpenseLines
                                              .Where(el => el.expenseLineId == command.expenseLineId)
                                              .SingleOrDefault();

            Expense existingExpense = expensesDb.Expenses
                                      .Where(e => e.expenseId == command.expenseId)
                                      .SingleOrDefault();

            // Check any IDs or foreign keys are correct
            // Should be done for *all* adds/updates to expenses
            if ((command.expenseLineId != 0) &&
                (existingExpenseLine == null))
            {
                validationResults.Add(new ValidationResult("ID",
                                                           $"No expense line exists with the ID: {command.expenseLineId}"));
            }
            if (existingExpense == null)
            {
                validationResults.Add(new ValidationResult("ExpenseID",
                                                           $"No expense exists with the ID: {command.expenseId}"));
            }
            // Check basic requirements for expenses
            if ((command.name == null) ||
                (command.name.Trim().Length == 0))
            {
                validationResults.Add(new ValidationResult("Name",
                                                           "Name is required on an expense line"));
            }

            return(validationResults);
        }
Beispiel #4
0
        public async Task <IActionResult> PutExpenseLine(int id, ExpenseLine expenseLine)
        {
            if (id != expenseLine.Id)
            {
                return(BadRequest());
            }

            _context.Entry(expenseLine).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExpenseLineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 /// <summary>
 /// Constructor from an expense line
 /// </summary>
 /// <param name="expenseLine"></param>
 // TODO remove this constructor
 public AddUpdateExpenseLineInfo(ExpenseLine expenseLine)
 {
     this.expenseLineId = expenseLine.expenseLineId;
     this.name          = expenseLine.name;
     this.amount        = expenseLine.amount;
     this.expenseId     = expenseLine.expenseId;
 }
Beispiel #6
0
        /// <summary>
        /// Handle the command.
        /// </summary>
        /// <param name="command"></param>
        public void Handle(DeleteExpenseLineInfo command)
        {
            ExpenseLine expenseLineToDelete = expenseDb.ExpenseLines
                                              .Where(e => e.expenseLineId == command.expenseLineId)
                                              .SingleOrDefault();

            expenseDb.ExpenseLines.Remove(expenseLineToDelete);

            expenseDb.SaveChanges();
        }
        /// <summary>
        /// This handles the command making all the required changes
        /// to the database.
        /// </summary>
        /// <param name="command"></param>
        public void Handle(AddUpdateExpenseLineInfo command)
        {
            ExpenseLine existingLine = expenseDb.ExpenseLines.Where(e => e.expenseLineId == command.expenseLineId)
                                       .SingleOrDefault();

            if (existingLine == null)
            {
                expenseDb.ExpenseLines.Add(command.GetExpenseLine());
            }
            else
            {
                expenseDb.Entry(existingLine).CurrentValues.SetValues(command);
            }

            expenseDb.SaveChanges();
        }
Beispiel #8
0
        public void ClearExpenseLines(ExpenseReport er)
        {
            List <ExpenseLine> ELs = new List <ExpenseLine>();

            // Remove EL from list (iterate backward to be safe)
            for (int i = er.ExpenseLines.Count - 1; i >= 0; i--)
            {
                ELs.Add(er.ExpenseLines[i]);
                er.RemoveLine(er.ExpenseLines[i]);
            }

            // Destroy all ELs
            for (int i = ELs.Count - 1; i >= 0; i--)
            {
                ExpenseLine toRemove = ELs[i];
                //ExpenseLine toRemove = Db.ExpenseLines.SingleOrDefault(el => el.Id == ELs[i].Id);
                if (toRemove != null)
                {
                    Db.ExpenseLines.Remove(toRemove);
                }
            }
            Db.SaveChanges();
        }
Beispiel #9
0
 public async Task <bool> DeleteExpenseLine(ExpenseLine ExpenseLine)
 {
     _context.Remove(ExpenseLine);
     return((await _context.SaveChangesAsync()) > 0);
 }
Beispiel #10
0
        public async Task <bool> UpdateExpenseLineAsync(int ExpenseId, ExpenseLine ExpenseLine)
        {
            ExpenseLine.ExpenseId = ExpenseId;

            return((await _context.SaveChangesAsync()) > 0);
        }
Beispiel #11
0
        /*
         * ------------------------------------------------------------
         * Initalize the DB with test data-----------------------------
         * ------------------------------------------------------------
         */
        public void InitializeDatabase()
        {
            #region Create services

            Services = new List <Service> {
                new Service("Informatique d'entreprise"),            //0
                new Service("Direction"),                            //1
                new Service("Compta"),                               //2
                new Service("RH"),                                   //3
                new Service("Commerce, Coloriages et Consultation"), //4
                new Service("Gestion des flux animaliers"),          //5
                new Service("Positionnement stratégique digitalisé") //6
            };

            #endregion

            #region Create collaborators
            Collaborators = new List <Collaborator> {
                new Collaborator("Morgan", "FEURTE", "mo", EncodeMD5("go")),
                new Collaborator("Minh", "NGUYEN", "cds", EncodeMD5("cds")),
                new Collaborator("Adrien", "LAVILLONNIERE", "adm", EncodeMD5("adm")),
                new Collaborator("Jeffrey", "GONCALVES", "j", EncodeMD5("g")),
                new Collaborator("Yao", "SHI", "cpt", EncodeMD5("cpt")),
                new Collaborator("Arthur", "BINELLI", "a", EncodeMD5("b")),
                new Collaborator("Thibal", "WITCZAK", "t", EncodeMD5("w")),
                new Collaborator("Floriab", "LE PALLEC", "f", EncodeMD5("lp")),
                new Collaborator("Oubar", "MAYAKI", "o", EncodeMD5("m")),
                new Collaborator("Nathon", "BONNARD", "n", EncodeMD5("b")),
                new Collaborator("Momo", "BELDI", "momo", EncodeMD5("b")),
                new Collaborator("Mathias", "BAZON", "mat", EncodeMD5("baz")),
                new Collaborator("Albon", "DESCOTTES", "alb", EncodeMD5("d")),
                new Collaborator("Arnaud", "GAY-BAUER", "ar", EncodeMD5("no")),
                new Collaborator("Coronton", "MONSCOUR", "coco", EncodeMD5("mons")),
                new Collaborator("Olodie", "LOM", "lom", EncodeMD5("olo")),
                new Collaborator("Kevon", "LOCOSTE", "kvn", EncodeMD5("kvn"))
            };
            #endregion

            #region Add coll to services

            // Add coll to services

            AddToService(2, 0); //mow le cds compta
            AddToService(1, 1); //minh le cds PDG
            AddToService(1, 2); //dadri le user + admin

            AddToService(0, 3); //jaff le CDS normal
            AddToService(2, 4); //yao le compta normal


            AddToService(3, 6);  //thib le RH normal
            AddToService(3, 7);  //flo le RH normal

            AddToService(4, 8);  //oubar le cds consultation
            AddToService(4, 9);  //nathon le user normal

            AddToService(3, 10); //momo le CDS RH

            AddToService(5, 11); //mathias le cds animaux
            AddToService(5, 5);  //arthur  user animaux

            AddToService(4, 12); //alban user consultation
            AddToService(0, 13); //arno user info

            AddToService(0, 14); //corentin user direction

            AddToService(2, 15); //elodie user compta

            AddToService(6, 16); //kvn cds Positionnement stratégique digitalisé

            #endregion

            #region Add admin roles

            // Add admin role to Adrien
            Collaborators[2].Role = Roles.ADMIN;

            //Add CHIEF roles to other people
            Collaborators[3].Role  = Roles.CHIEF;            //Jeffrey is now CDS info
            Collaborators[1].Role  = Roles.CHIEF;            //Minh is now CDS Direction (PDG)
            Collaborators[0].Role  = Roles.CHIEF;            //Morgan is now CDS Compta
            Collaborators[11].Role = Roles.CHIEF;            //Mathias is now CDS Animaux
            Collaborators[8].Role  = Roles.CHIEF;            //Oubar is now CDS Consultation
            Collaborators[16].Role = Roles.CHIEF;            //KVN is now CDS Digital
            Collaborators[10].Role = Roles.CHIEF;            //Momo is DRH

            #endregion

            #region Initialize notifications
            Notifications = new ConcurrentBag <Notification>()
            {
                new Notification(Collaborators[2], Collaborators[2], NotificationType.INFORMATION, NotificationResult.VALIDATION),
                new Notification(Collaborators[1], Collaborators[2], NotificationType.INFORMATION, NotificationResult.REFUSAL),
                new Notification(Collaborators[3], Collaborators[1], NotificationType.INFORMATION, NotificationResult.VALIDATION),
                new Notification(Collaborators[4], Collaborators[4], NotificationType.INFORMATION, NotificationResult.VALIDATION),
                new Notification(Collaborators[5], Collaborators[5], NotificationType.INFORMATION, NotificationResult.VALIDATION)
            };

            #endregion

            #region Create some missions
            Missions = new List <Mission> {
                new Mission("Mission A", DateTime.Today, new DateTime(2019, 5, 1), MissionStatus.IN_PROGRESS),
                new Mission("Mission B", new DateTime(2019, 2, 9), new DateTime(2019, 3, 1), MissionStatus.PLANNED),
                new Mission("Mission C", new DateTime(2018, 12, 25), new DateTime(2018, 12, 26), MissionStatus.CANCELED),
                new Mission("Mission D", new DateTime(2018, 2, 25), new DateTime(2018, 2, 26), MissionStatus.COMPLETED),
                new Mission("Mission E", new DateTime(2019, 2, 6), new DateTime(2019, 3, 1), MissionStatus.PLANNED),
                new Mission("Mission F", new DateTime(2019, 1, 9), new DateTime(2019, 11, 1), MissionStatus.PLANNED),
                new Mission("Mission G", new DateTime(2019, 1, 2), new DateTime(2019, 1, 4), MissionStatus.IN_PROGRESS),
                new Mission("Mission H", new DateTime(2019, 2, 11), MissionStatus.IN_PROGRESS)
            };
            #endregion

            #region Adding every lists above to the database

            foreach (Service s in Services)
            {
                Db.Services.Add(s);
            }

            foreach (Collaborator c in Collaborators)
            {
                Db.Collaborators.Add(c);
            }

            foreach (Mission m in Missions)
            {
                Db.Missions.Add(m);
            }

            foreach (Notification n in Notifications)
            {
                Db.Notifications.Add(n);
            }

            Db.SaveChanges();
            #endregion

            #region Assign missions to collaborators and setting chiefId

            GetCollaborator("Arthur", "BINELLI").Missions.Add(GetMission("Mission A"));
            GetCollaborator("Arthur", "BINELLI").Missions.Add(GetMission("Mission C"));
            GetCollaborator("Arthur", "BINELLI").Missions.Add(GetMission("Mission E"));

            GetCollaborator("Jeffrey", "GONCALVES").Missions.Add(GetMission("Mission A"));
            GetCollaborator("Jeffrey", "GONCALVES").Missions.Add(GetMission("Mission F"));

            GetCollaborator("Nathon", "BONNARD").Missions.Add(GetMission("Mission B"));
            GetCollaborator("Nathon", "BONNARD").Missions.Add(GetMission("Mission E"));
            GetCollaborator("Nathon", "BONNARD").Missions.Add(GetMission("Mission F"));

            GetCollaborator("Floriab", "LE PALLEC").Missions.Add(GetMission("Mission D"));
            GetCollaborator("Floriab", "LE PALLEC").Missions.Add(GetMission("Mission H"));

            //Adrien is coll2, Adrien gets all the missions because he is admin
            //GetCollaborator("Adrien", "LAVILLONNIERE").Missions = Missions;
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission A"));
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission B"));
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission C"));
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission D"));
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission E"));
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission F"));
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission G"));
            GetCollaborator("Adrien", "LAVILLONNIERE").Missions.Add(GetMission("Mission H"));

            GetCollaborator("Morgan", "FEURTE").Missions.Add(GetMission("Mission A"));
            GetCollaborator("Morgan", "FEURTE").Missions.Add(GetMission("Mission B"));
            GetCollaborator("Morgan", "FEURTE").Missions.Add(GetMission("Mission C"));


            // Setting chief ID for each mission
            Missions[0].ChiefId = GetCollaborator("Morgan", "FEURTE").Id;

            Missions[1].ChiefId = GetCollaborator("Minh", "NGUYEN").Id;

            Missions[2].ChiefId = GetCollaborator("Jeffrey", "GONCALVES").Id;

            Missions[3].ChiefId = GetCollaborator("Oubar", "MAYAKI").Id;
            Missions[4].ChiefId = GetCollaborator("Oubar", "MAYAKI").Id;
            Missions[5].ChiefId = GetCollaborator("Oubar", "MAYAKI").Id;

            Missions[6].ChiefId = GetCollaborator("Mathias", "BAZON").Id;

            Missions[7].ChiefId = GetCollaborator("Momo", "BELDI").Id;

            Db.SaveChanges();

            #endregion

            #region Create expense reports

            ExpenseReports = new List <ExpenseReport>()
            {
                new ExpenseReport(GetCollaborator("Arthur", "BINELLI"), Month.DECEMBER, 2018, ExpenseReportStatus.PENDING_APPROVAL_2, false),
                new ExpenseReport(GetCollaborator("Arthur", "BINELLI"), Month.NONE, 1990, ExpenseReportStatus.APPROVED, true),
                new ExpenseReport(GetCollaborator("Floriab", "LE PALLEC"), Month.DECEMBER, 2018, ExpenseReportStatus.PENDING_APPROVAL_1, false),
                new ExpenseReport(GetCollaborator("Oubar", "MAYAKI"), Month.JANUARY, 2019, ExpenseReportStatus.UNSENT, false),
            };

            Db.SaveChanges();

            // by Yao
            ExpenseLines = new List <ExpenseLine>()
            {
                new ExpenseLine(GetMission("Mission A"), LineType.HOTEL, "Minh NGUYEN", "T Tower", 1000.0f, new DateTime(2019, 3, 4), "ProjetGL-recueil des besoins.pdf"),                                        // by Yao, "trumptower.pdf"
                new ExpenseLine(GetMission("Mission B"), LineType.RESTAURANT, "Jeffrey GONCALVES", "Tower restaurant", 8000.0f, new DateTime(2019, 1, 2), "Cours Polytech - Paris XI -Atelier GL Cours1 v5.pdf"), // by Yao, "restau1.pdf"
                new ExpenseLine(GetMission("Mission C"), LineType.TAXI, "Jeffrey GONCALVES", "Jafar Taxi", 15.98f, new DateTime(2019, 3, 4), ""),                                                                 //by Yao, "taxig7.pdf"
                new ExpenseLine(GetMission("Mission E"), LineType.OTHER, "Jeffrey GONCALVES", "Jafar Other", 80010.0f, new DateTime(2019, 1, 2), "Cours Polytech - Paris XI -Atelier GL COURS RAPPELS V4.pdf")    //by Yao, "russia.pdf"
            };

            // Lignes de l'ER 1 (arthur)
            foreach (ExpenseLine el in ExpenseLines)
            {
                ExpenseReports[0].AddLine(el);
            }

            //Avance pour Arthur
            ExpenseLine el1 = new ExpenseLine(GetMission(6), LineType.RESTAURANT, "Pepperoni Pizza", 10.0f, new DateTime(2019, 1, 7), "pizza.pdf");
            el1.IsAdvance       = true;
            el1.Validated       = true;
            el1.FinalValidation = true;
            ExpenseLine el2 = new ExpenseLine(GetMission(2), LineType.HOTEL, "Pepperoni Arthur", 10.0f, new DateTime(2019, 1, 8), "hotelflo.pdf");
            el2.IsAdvance       = true;
            el2.Validated       = true;
            el2.FinalValidation = true;

            ExpenseReports[1].AddLine(el1);
            ExpenseReports[1].AddLine(el2);

            // Ligne de l'ER 2 (flo)
            ExpenseReports[2].AddLine(new ExpenseLine(GetMission(6), LineType.RESTAURANT, "Pepperoni Pizza", 10.0f, new DateTime(2019, 1, 7), "pizza.pdf"));
            ExpenseReports[2].AddLine(new ExpenseLine(GetMission(2), LineType.HOTEL, "Pepperoni Florian", 10.0f, new DateTime(2019, 1, 8), "hotelflo.pdf"));
            // Lignes de l'ER 4 (jeffrey). Jeffrey n'a aucune mission à effectuer actuellement
            //ExpenseReports[3].AddLine(new ExpenseLine(GetMission(1), LineType.RESTAURANT, "Jeffrey GONCALVES", "Simon Burger", 10.0f, new DateTime(2019, 1, 5), "trumpburger.pdf"));
            //ExpenseReports[3].AddLine(new ExpenseLine(GetMission(3), LineType.HOTEL, "Minh NGUYEN", "Jafar Hotel", 10.0f, new DateTime(2019, 1, 5), "hotel.pdf"));

            //foreach (ExpenseReport er in ExpenseReports) {
            //    Db.ExpenseReports.Add(er);
            //}

            Db.SaveChanges();
            #endregion

            #region Create leaves

            List <Leave> leaves = new List <Leave>()
            {
                new Leave(LeaveStatus.PENDING_APPROVAL_1, LeaveType.OTHER, GetCollaborator("Morgan", "FEURTE"), new DateTime(2019, 2, 05), new DateTime(2019, 2, 15), "Matin", "Matin"),
                new Leave(LeaveStatus.REFUSED, LeaveType.PAID, GetCollaborator("Oubar", "MAYAKI"), new DateTime(2019, 2, 3), new DateTime(2019, 2, 6), "Matin", "Matin"),
                //new Leave(LeaveStatus.APPROVED, LeaveType.PAID, GetCollaborator("Oubar", "MAYAKI"), new DateTime(2019, 1, 4), new DateTime(2019, 1, 12)),

                new Leave(LeaveStatus.PENDING_APPROVAL_1, LeaveType.PAID, GetCollaborator("Floriab", "LE PALLEC"), new DateTime(2019, 2, 9), new DateTime(2019, 2, 11), "Matin", "Matin"),

                new Leave(LeaveStatus.APPROVED, LeaveType.PAID, GetCollaborator("Nathon", "BONNARD"), new DateTime(2019, 2, 27), new DateTime(2019, 3, 1), "Matin", "Après-midi"),


                new Leave(LeaveStatus.PENDING_APPROVAL_1, LeaveType.RTT, GetCollaborator("Nathon", "BONNARD"), new DateTime(2019, 3, 19), new DateTime(2019, 3, 21), "Après-midi", "Après-midi"),

                //new Leave(LeaveStatus.PENDING_APPROVAL_2, LeaveType.RTT, GetCollaborator("Momo", "BELDI"), new DateTime(2019, 2, 1), new DateTime(2019, 2, 8)),
                //new Leave(LeaveStatus.APPROVED, LeaveType.PAID, GetCollaborator("Thibal", "WITCZAK"), new DateTime(2019, 1, 05), new DateTime(2019, 2, 15)),
                new Leave(LeaveStatus.PENDING_APPROVAL_1, LeaveType.PAID, GetCollaborator("Coronton", "MONSCOUR"), new DateTime(2019, 2, 14), new DateTime(2019, 2, 25), "Après-midi", "Après-midi"),

                new Leave(LeaveStatus.REFUSED, LeaveType.RTT, GetCollaborator("Thibal", "WITCZAK"), new DateTime(2018, 12, 05), new DateTime(2019, 1, 15), "Matin", "Matin"),
                new Leave(LeaveStatus.APPROVED, LeaveType.PAID, GetCollaborator("Minh", "NGUYEN"), new DateTime(2019, 3, 4), new DateTime(2019, 9, 18), "Après-midi", "Matin")
            };

            foreach (Leave l in leaves)
            {
                Db.Leaves.Add(l);
            }

            GetCollaborator("Thibal", "WITCZAK").NbPaid = 5;
            GetCollaborator("Thibal", "WITCZAK").NbRTT  = 10;

            GetCollaborator("Oubar", "MAYAKI").NbPaid = 15;
            GetCollaborator("Oubar", "MAYAKI").NbRTT  = 18;

            GetCollaborator("Nathon", "BONNARD").NbPaid = 5;
            GetCollaborator("Nathon", "BONNARD").NbRTT  = 5;

            GetCollaborator("Floriab", "LE PALLEC").NbPaid = 11;
            GetCollaborator("Floriab", "LE PALLEC").NbRTT  = 9;

            GetCollaborator("Minh", "NGUYEN").NbPaid = 100;
            GetCollaborator("Minh", "NGUYEN").NbRTT  = 900;


            Db.SaveChanges();

            #endregion
        }