public ActionResult Create([Bind(Include = "EventId,Venue,Location,StartDateTime,EndDateTime,ClubId")] ClubEvent clubEvent)
        {
            if (ModelState.IsValid)
            {
                db.ClubEvents.Add(clubEvent);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClubId = new SelectList(db.Clubs, "ClubId", "ClubName", clubEvent.ClubId);
            return(View(clubEvent));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "MemberId,ClubId,StudentId,Approved")] Member member)
        {
            if (ModelState.IsValid)
            {
                db.Members.Add(member);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClubId    = new SelectList(db.Clubs, "ClubId", "ClubName", member.ClubId);
            ViewBag.StudentId = new SelectList(db.Students, "StudentId", "FirstName", member.StudentId);
            return(View(member));
        }
Example #3
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }
        }
Example #4
0
        // Delete Adherent
        private async void SupprimerBtn_Click(object sender, EventArgs e)
        {
            // Get current adherent
            Adherent adhToRemove = adherentBindingSource.Current as Adherent;

            // Get adherent to remove from db
            try
            {
                using (ClubDbContext context = new ClubDbContext())
                {
                    var userToDelete = context.Users
                                       .Include(u => u.Adherent)
                                       .SingleOrDefault(u => u.AdherentId == adhToRemove.CodeAdh);
                    var correspondingAdherent = context.Adherents
                                                .Include(u => u.PreferredActivities)
                                                .Include(u => u.Seances)
                                                .SingleOrDefault(a => a.CodeAdh == adhToRemove.CodeAdh);
                    var prefActivities = correspondingAdherent.PreferredActivities.ToList();
                    foreach (var act in prefActivities)
                    {
                        correspondingAdherent.PreferredActivities.Remove(act);
                    }
                    var seances = correspondingAdherent.Seances.ToList();
                    foreach (var seance in seances)
                    {
                        correspondingAdherent.Seances.Remove(seance);
                    }
                    context.Adherents.Remove(correspondingAdherent);
                    context.SaveChanges();
                    context.Users.Remove(userToDelete);
                    context.SaveChanges();
                }
                adherents_Load(sender, e);
            }
            catch (ArgumentNullException ex)
            {
                MetroFramework.MetroMessageBox.Show(this,
                                                    "Aucun adhérent n'est séléctionnée ou bien la" +
                                                    " base de données est vide.",
                                                    "Pas d'adhérent séléctionné",
                                                    MessageBoxButtons.OK,
                                                    MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #5
0
        private void SubmitBtn_Click(object sender, EventArgs e)
        {
            ICollection <Activite> preffered = new HashSet <Activite>();

            // Perform Submit Logic (set the role to Non Payed Client !) :)
            try
            {
                if (activiteBindingSource.Count != 0)
                {
                    using (ClubDbContext context = new ClubDbContext())
                    {
                        context.Users.SingleOrDefault(u => u.Id == currenUser.Id).Role = User.NonPayedClient;
                        context.SaveChanges();
                    }
                }
                else
                {
                    MetroFramework.MetroMessageBox.Show(this,
                                                        "Veuillez" +
                                                        "remplire votre liste des Activités préfférés!",
                                                        "Données Non Valides",
                                                        MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            // call the event
            OnSetPrefferedActivities();
        }
Example #6
0
        private void PayementBtn_Click(object sender, EventArgs e)
        {
            var adherentToPay = adherentBindingSource.Current as Adherent;

            if (adherentToPay == null)
            {
                UserErrors.Add("Veuillez séléctionner un adhérent pour éffectuer le payement!");
            }
            if (ExpirationDate.Value.Date + ExpirationTime.Value.TimeOfDay < DateTime.Now)
            {
                UserErrors.Add("Veuillez Entrer une date d'éxpiration valide !");
            }
            if (UserErrors.Count > 0)
            {
                MetroFramework.MetroMessageBox.Show(this,
                                                    string.Join("\n", UserErrors),
                                                    "Données Non Valides",
                                                    MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error);
                // Clear errors for another use and quit
                UserErrors.Clear();
                return;
            }

            using (ClubDbContext context = new ClubDbContext())
            {
                var UserInDb = context.Users.SingleOrDefault(u => u.AdherentId == adherentToPay.CodeAdh);
                var CorrespondingAdherent = context.Adherents.SingleOrDefault(a => a.CodeAdh == adherentToPay.CodeAdh);
                UserInDb.Role = User.Client;
                CorrespondingAdherent.ExpirationDate = ExpirationDate.Value.Date + ExpirationTime.Value.TimeOfDay;
                context.SaveChanges();
            }
            Subscribtions_Load(sender, e);
        }
Example #7
0
        private void DeleteActivityBtn_Click(object sender, EventArgs e)
        {
            // Perform Delete Activity Logic
            if (activiteBindingSource.Count != 0)
            {
                var activityToRemove = activiteBindingSource.Current as Activite;
                using (ClubDbContext context = new ClubDbContext())
                {
                    var activityInDb = context.Activites
                                       .SingleOrDefault(a => a.CodeActivite == activityToRemove.CodeActivite);
                    context.Adherents.SingleOrDefault(a => a.CodeAdh == currentUser.AdherentId)
                    .PreferredActivities.Remove(activityInDb);
                    context.SaveChanges();
                }
                Activities_Load(sender, e);
            }

            else
            {
                MetroFramework.MetroMessageBox.Show(this,
                                                    "Veuillez Selectionner une ligne dans le tableau ou bien " +
                                                    "remplire votre liste des Activités préfférés si elle est vide!",
                                                    "Données Non Valides",
                                                    MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error);
            }
        }
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);
            _context.SaveChanges();
        }
Example #10
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Example #11
0
        public void SeedStudents(ApplicationDbContext current)
        {
            List <Student> selectedStudents = new List <Student>();

            using (ClubDbContext ctx = new ClubDbContext())
            {
                var randomStudentSet = ctx.Students
                                       .Select(s => new { s.StudentId, r = Guid.NewGuid() });

                List <string> subset = randomStudentSet
                                       .OrderBy(s => s.r)
                                       .Select(s => s.StudentId).Take(10).ToList();

                foreach (string s in subset)
                {
                    selectedStudents.Add(
                        ctx.Students.First(st => st.StudentId == s)
                        );
                }

                Club chosen = ctx.Clubs.First();

                foreach (Student s in selectedStudents)
                {
                    ctx.Members.AddOrUpdate(m => m.StudentId,
                                            new Member
                    {
                        ClubId    = chosen.ClubId,
                        StudentId = s.StudentId
                    });
                }
                ctx.SaveChanges();
            }

            foreach (Student s in selectedStudents)
            {
                current.Users.AddOrUpdate(u => u.StudentId,
                                          new ApplicationUser
                {
                    StudentId      = s.StudentId,
                    UserName       = s.StudentId + "@mail.itsligo.ie",
                    Email          = s.StudentId + "@mail.itsligo.ie",
                    EmailConfirmed = true,
                    DateJoined     = DateTime.Now,
                    PasswordHash   = new PasswordHasher().HashPassword("s" + s.StudentId + "$1"),
                    SecurityStamp  = Guid.NewGuid().ToString(),
                });
            }

            current.SaveChanges();
        }
Example #12
0
        // Affect Seance to coach logic
        private void AffecterSeanceBtn_Click(object sender, EventArgs e)
        {
            if (currentSeance != null && currentCoach != null)
            {
                try
                {
                    using (ClubDbContext context = new ClubDbContext())
                    {
                        var coachInDb = context.Coaches
                                        .Include(c => c.Activites)
                                        .Include(c => c.Seances)
                                        .SingleOrDefault(c => c.CodeCoach == currentCoach.CodeCoach);

                        var seanceInDb = context.Seances
                                         .Include(s => s.Coach)
                                         .Include(s => s.Activites)
                                         .Include(s => s.Salle)
                                         .SingleOrDefault(s => s.CodeSeance == currentSeance.CodeSeance);
                        if (coachInDb != null && seanceInDb != null)
                        {
                            coachInDb.Seances.Add(seanceInDb);
                            context.SaveChanges();
                        }
                        MetroFramework.MetroMessageBox.Show(this,
                                                            "La séance dont le code est " + seanceInDb.CodeSeance
                                                            + " qui a comme horaire: " + seanceInDb.DebutSeance
                                                            + " a bien été associée au coach: " + coachInDb.Nom +
                                                            " " + coachInDb.Prenom + " !",
                                                            "Séance afféctée avec succés",
                                                            MessageBoxButtons.OK,
                                                            MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox
                    .Show(ex.Message);
                }
            }
            else
            {
                // show added message to display No Seance selected error
                MetroFramework.MetroMessageBox.Show(this,
                                                    "Vous n'avez séléctionné aucunne séance ou bien" +
                                                    "La base de donnée ne contiens aucunne séance !",
                                                    "Pas de Seance selectionnées",
                                                    MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error);
            }
        }
Example #13
0
        public RedirectResult Join(int id)
        {
            using (ApplicationDbContext ctx = new ApplicationDbContext())
            {
                ApplicationUser user = ctx.Users.Where(u => u.Email == User.Identity.Name).First();

                IQueryable <Member> members = db.Members.Where(m => m.ClubId == id && m.StudentId == user.StudentId);

                if (members.Count() == 0)
                {
                    db.Members.Add(new Member
                    {
                        ClubId    = id,
                        StudentId = user.StudentId,
                        Approved  = false
                    });

                    db.SaveChanges();
                }
            }

            return(Redirect(string.Format("/Clubs/Details/{0}", id)));
        }
Example #14
0
        // Perform dicipline affectation logic
        private void AffecterDicipline_Click(object sender, EventArgs e)
        {
            if (activitiesCB.SelectedItem.ToString() != "Choisir Votre Discipline" &&
                activitiesCB.SelectedItem.ToString() != string.Empty)
            {
                var currentCoach = (coachBindingSource.Current != null)
                    ? coachBindingSource.Current as Coach
                    : null;
                if (currentCoach != null)
                {
                    using (ClubDbContext context = new ClubDbContext())
                    {
                        var coachToModify = context.Coaches
                                            .SingleOrDefault(c => c.CodeCoach == currentCoach.CodeCoach);

                        if (coachToModify.Activites.Count <= 2)
                        {
                            var activityToAdd = context.Activites
                                                .SingleOrDefault(a => a.Nom == activitiesCB.SelectedItem.ToString());
                            coachToModify.Activites.Add(activityToAdd);
                            context.SaveChanges();
                            MetroFramework.MetroMessageBox.Show(this,
                                                                "La discipline " + activityToAdd.Nom + " a bien été afféctée " +
                                                                "au coach " + coachToModify.Nom + " !",
                                                                "Discipline affécté avec succès",
                                                                MessageBoxButtons.OK,
                                                                MessageBoxIcon.Information);
                        }
                        else
                        {
                            MetroFramework.MetroMessageBox.Show(this,
                                                                "Désolé vous ne pouvez pas affecter plus de 2 disciplines " +
                                                                "à un coach !",
                                                                "Erreur d'affectation de discipline",
                                                                MessageBoxButtons.OK,
                                                                MessageBoxIcon.Error);
                        }
                    }
                }
            }


            // disable the label
            AffecterDicipline.Enabled   = false;
            AffecterDicipline.ForeColor = Color.Gray;
            // set ddl to 0
            activitiesCB.SelectedIndex = 0;
        }
        private void CreateDefaultTenant()
        {
            // Default tenant

            var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName);

            if (defaultTenant == null)
            {
                defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName);

                var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                if (defaultEdition != null)
                {
                    defaultTenant.EditionId = defaultEdition.Id;
                }

                _context.Tenants.Add(defaultTenant);
                _context.SaveChanges();
            }
        }
Example #16
0
 private void UnsubscribeBtn_Click(object sender, EventArgs e)
 {
     // Perform Unsubscribe Logic
     if (UnsubscribeTB.Text != string.Empty)
     {
         try
         {
             using (ClubDbContext context = new ClubDbContext())
             {
                 var userToDelete = context.Users
                                    .Include(u => u.Adherent)
                                    .SingleOrDefault(u => u.Id == currentUser.Id);
                 var correspondingAdherent = context.Adherents
                                             .Include(u => u.PreferredActivities)
                                             .Include(u => u.Seances)
                                             .SingleOrDefault(u => u.CodeAdh == currentUser.AdherentId);
                 var prefActivities = correspondingAdherent.PreferredActivities.ToList();
                 foreach (var act in prefActivities)
                 {
                     correspondingAdherent.PreferredActivities.Remove(act);
                 }
                 var seances = correspondingAdherent.Seances.ToList();
                 foreach (var seance in seances)
                 {
                     correspondingAdherent.Seances.Remove(seance);
                 }
                 context.Adherents.Remove(correspondingAdherent);
                 context.Users.Remove(userToDelete);
                 context.SaveChanges();
             }
             Application.Restart();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Example #17
0
        private void DeleteSeanceBtn_Click(object sender, EventArgs e)
        {
            // Perform Delete Logic
            var seanceToDelete = seanceBindingSource.Current as Seance;

            try
            {
                if (seanceToDelete != null)
                {
                    using (ClubDbContext context = new ClubDbContext())
                    {
                        var seanceInDb = context.Seances
                                         .Include(s => s.Activites)
                                         .Include(s => s.Adherents)
                                         .SingleOrDefault(s => s.CodeSeance == seanceToDelete.CodeSeance);
                        var adherents = seanceInDb.Adherents.ToList();
                        var activites = seanceInDb.Activites.ToList();
                        foreach (var activity in activites)
                        {
                            seanceInDb.Activites.Remove(activity);
                        }
                        foreach (var adherent in adherents)
                        {
                            seanceInDb.Adherents.Remove(adherent);
                        }
                        context.Seances.Remove(seanceInDb);
                        context.SaveChanges();
                    }
                    Activities_Load(sender, e);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void CreateRolesAndUsers()
        {
            // Admin role

            var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == _tenantId && p.RoleId == adminRole.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new ClubAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = _tenantId,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRole.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user

            var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName);

            if (adminUser == null)
            {
                adminUser                  = User.CreateTenantAdminUser(_tenantId, "*****@*****.**");
                adminUser.Password         = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe");
                adminUser.IsEmailConfirmed = true;
                adminUser.IsActive         = true;

                _context.Users.Add(adminUser);
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();
            }
        }
        private void CreateHostRoleAndUsers()
        {
            // Admin role for host

            var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role for host

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new ClubAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = null,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRoleForHost.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user for host

            var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (adminUserForHost == null)
            {
                var user = new User
                {
                    TenantId         = null,
                    UserName         = AbpUserBase.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    IsActive         = true
                };

                user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe");
                user.SetNormalizedNames();

                adminUserForHost = _context.Users.Add(user).Entity;
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

                _context.SaveChanges();
            }
        }
Example #20
0
        private void AddActivityBtn_Click(object sender, EventArgs e)
        {
            if (AddActivityBtn.Text.Equals("Ajouter Activitée"))
            {
                // Enable form to user
                ActivityFormEnabled(true);
                SeanceFormEnabled(false);

                // Change UI
                ActivityFormColors(Color.WhiteSmoke);

                // default text
                ActivityFormInitializeText();

                // Change button text
                AddActivityBtn.Text = "Sauvegarder";

                // disable other buttons
                DeleteActivityBtn.Enabled = false;
                ModifySeanceBtn.Enabled   = false;
                // Load Activities from db
                using (ClubDbContext context = new ClubDbContext())
                {
                    var activityNamesInDb = context.Activites.ToList();
                    foreach (var activity in activityNamesInDb)
                    {
                        activities.Add(activity.Nom);
                    }
                }
                // bind data to the cb collection of values
                ActivitiesCB.DataSource = activities;

                // Add a new field to the binding source
                activiteBindingSource.Add(new Activite());
                activiteBindingSource.MoveLast();
            }
            else if (AddActivityBtn.Text.Equals("Sauvegarder"))
            {
                // Perform Add Logic
                if (ActivitiesCB.SelectedValue.ToString() != "Activités" &&
                    ActivitiesCB.SelectedValue != null)
                {
                    var current = activiteBindingSource.Current as Activite;
                    using (ClubDbContext context = new ClubDbContext())
                    {
                        // Pick the activity object from db from cb selected activity name
                        current = context.Activites
                                  .SingleOrDefault(a => a.Nom == ActivitiesCB.SelectedValue.ToString());

                        // add the activity to current adherent prefered activities
                        context.Adherents.SingleOrDefault(a => a.CodeAdh == currentUser.AdherentId)
                        .PreferredActivities.Add(current);

                        context.SaveChanges();
                    }
                }
                Activities_Load(sender, e);
                // Disable form to user
                ActivityFormEnabled(false);
                SeanceFormEnabled(true);

                // Change Ui
                ActivityFormColors(Color.FromArgb(95, 77, 221));

                // Change button text
                AddActivityBtn.Text = "Ajouter Activitée";

                // Enable other buttons
                DeleteActivityBtn.Enabled = true;
                ModifySeanceBtn.Enabled   = true;
            }
        }
Example #21
0
        private void ModifySeanceBtn_Click(object sender, EventArgs e)
        {
            // Perform Modify Logic
            var seanceToAdd = seanceBindingSource.Current as Seance;

            if (seanceToAdd != null)
            {
                seanceToAdd.DebutSeance = SeanceDate.Value.Date + SeanceTime.Value.TimeOfDay;

                DateTime min = new DateTime(seanceToAdd.DebutSeance.Year
                                            , seanceToAdd.DebutSeance.Month
                                            , seanceToAdd.DebutSeance.Day
                                            , 7
                                            , 0
                                            , 0);
                DateTime max = new DateTime(seanceToAdd.DebutSeance.Year
                                            , seanceToAdd.DebutSeance.Month
                                            , seanceToAdd.DebutSeance.Day
                                            , 21
                                            , 0
                                            , 0);

                if (seanceToAdd.DebutSeance < min || seanceToAdd.DebutSeance > max)
                {
                    UserErrors.Add("Les Seances doivent respecter les horaires du club: \n" +
                                   "Ouverture: 7h00\n" +
                                   "Fermeture: 21h00.");
                }
                if (UserErrors.Count > 0)
                {
                    MetroFramework.MetroMessageBox.Show(this,
                                                        string.Join("\n", UserErrors),
                                                        "Données Non Valides",
                                                        MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                    // Clear errors for another use and quit
                    UserErrors.Clear();
                    return;
                }
                using (ClubDbContext context = new ClubDbContext())
                {
                    var seanceInDb = context.Adherents.Include(a => a.Seances)
                                     .SingleOrDefault(a => a.CodeAdh == currentUser.AdherentId)
                                     .Seances
                                     .SingleOrDefault(s => s.CodeSeance == seanceToAdd.CodeSeance);
                    seanceInDb.DebutSeance = seanceToAdd.DebutSeance;
                    context.SaveChanges();
                }
                Activities_Load(sender, e);
            }
            else
            {
                MetroFramework.MetroMessageBox.Show(this,
                                                    "Vous n'avez pas séléctionné une séance ou bien aucune séance ne vous est afféctée!",
                                                    "Aucune séance n'est séléctionnée",
                                                    MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error);
                // Clear errors for another use and quit
                UserErrors.Clear();
            }
        }
Example #22
0
        private void AddSeanceBtn_Click(object sender, EventArgs e)
        {
            if (AddSeanceBtn.Text.Equals("Ajouter Une Seance"))
            {
                // Enable form to user
                formEnabled(true);

                // Change UI
                formColors(Color.WhiteSmoke);

                // default text
                formTbInitializeText();

                // Change button text
                AddSeanceBtn.Text = "Sauvegarder";

                seanceBindingSource.Add(new Seance());
                seanceBindingSource.MoveLast();
            }
            else if (AddSeanceBtn.Text.Equals("Sauvegarder"))
            {
                // Perform Add Logic
                var seanceToAdd = seanceBindingSource.Current as Seance;
                seanceToAdd.Activites   = new List <Activite>();
                seanceToAdd.DebutSeance = SeanceDate.Value.Date + SeanceTime.Value.TimeOfDay;
                if (MinAdhTB.Text == string.Empty ||
                    MaxAdhTB.Text == string.Empty ||
                    ActivitiesCB.SelectedIndex == 0 ||
                    CoachsCB.SelectedIndex == 0 ||
                    SallesCB.SelectedIndex == 0)
                {
                    UserErrors.Add("Veuillez remplire tous les champs du formulaire !");
                }
                if (seanceToAdd.MinAdh <= 0)
                {
                    UserErrors.Add("Le nombre minimal d'adhérents doit etre supérieur à 0");
                }
                if (seanceToAdd.MaxAdh > 10)
                {
                    if (ActivitiesCB.SelectedItem.ToString() != "Musculation")
                    {
                        UserErrors.Add("Le nombre maximal d'adhérents doit etre inférieur ou égal à 10" +
                                       "Sauf pour la musculation.");
                    }
                    else if (ActivitiesCB.SelectedItem.ToString() == "Musculation" && seanceToAdd.MaxAdh > 30)
                    {
                        UserErrors.Add("Le nombre maximal d'adhérents doit etre inférieur ou égal à 30" +
                                       "pour la musculation.");
                    }
                }
                DateTime min = new DateTime(seanceToAdd.DebutSeance.Year
                                            , seanceToAdd.DebutSeance.Month
                                            , seanceToAdd.DebutSeance.Day
                                            , 7
                                            , 0
                                            , 0);
                DateTime max = new DateTime(seanceToAdd.DebutSeance.Year
                                            , seanceToAdd.DebutSeance.Month
                                            , seanceToAdd.DebutSeance.Day
                                            , 21
                                            , 0
                                            , 0);

                if (seanceToAdd.DebutSeance < min || seanceToAdd.DebutSeance > max)
                {
                    UserErrors.Add("Les Seances doivent respecter les horaires du club: \n" +
                                   "Ouverture: 7h00\n" +
                                   "Fermeture: 21h00.");
                }
                if (UserErrors.Count > 0)
                {
                    MetroFramework.MetroMessageBox.Show(this,
                                                        string.Join("\n", UserErrors),
                                                        "Données Non Valides",
                                                        MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                    // Clear errors for another use and quit
                    UserErrors.Clear();
                    return;
                }

                using (ClubDbContext context = new ClubDbContext())
                {
                    var activityToAdd = context.Activites
                                        .SingleOrDefault(a => a.Nom == ActivitiesCB.SelectedItem.ToString());
                    var coachToAdd = context.Coaches
                                     .SingleOrDefault(c => c.Nom == CoachsCB.SelectedItem.ToString());
                    var salleToAdd = context.Salles
                                     .SingleOrDefault(s => s.Discipline == SallesCB.SelectedItem.ToString());
                    seanceToAdd.Salle = salleToAdd;
                    seanceToAdd.Coach = coachToAdd;
                    seanceToAdd.Activites.Add(activityToAdd);
                    context.Seances.Add(seanceToAdd);
                    context.SaveChanges();
                }
                Activities_Load(sender, e);

                // Disable form to user
                formEnabled(false);

                // Change Ui
                formColors(Color.FromArgb(95, 77, 221));

                // Change button text
                AddSeanceBtn.Text = "Ajouter Une Seance";

                // Enable other buttons
                ModifySeanceBtn.Enabled = true;
                DeleteSeanceBtn.Enabled = true;
            }
        }