public void DeleteCoach()
        {
            try
            {
                Console.WriteLine("Enter Coach id:");
                string id = Console.ReadLine();
                int    tryint;

                while (!int.TryParse(id, out tryint))
                {
                    Console.WriteLine("Incorrect id! Try again ");
                    id = Console.ReadLine();
                }

                using (swimmingContext swimdb = new swimmingContext())
                {
                    ICoachManager <Coach> coachManager = new CoachRepository(swimdb);
                    coachManager.Delete(Convert.ToInt32(id));
                    Console.WriteLine("Coach is deleted");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        public void CanReadCoach()
        {
            // Arange
            var dbFactory       = new DatabaseFactory();
            var coachRepository = new CoachRepository(dbFactory);
            var unitOfWork      = new UnitOfWork(dbFactory);

            coachRepository.Add(new COACH
            {
                COACH_INTERNAL_ID = "1",
                PAYMENTRATE       = 120.2M,
                PAYOFFRATE        = 100.2M,
                PERSON            = new PERSON
                {
                    FIRSTNAME = "Milan",
                    LASTNAME  = "Milanovic",
                    EMAIL     = "*****@*****.**",
                    TELEPHONE = "0644325665"
                }
            });

            unitOfWork.Commit();

            // Act
            var coach = coachRepository.Get(c => c.COACH_INTERNAL_ID == "1");

            // Assert
            Assert.IsNotNull(coach, "coach doesn't exist");
        }
Пример #3
0
 public void GetCoachByIdTest()
 {
     var context = new Core.Data.CSBCDbContext();
     var testinit = new CSBCDbInitializer();
     var rep = new CoachRepository(context);
     var dt = rep.GetCoaches((testinit.CurrentSeason).SeasonID);
     Assert.IsTrue(dt.Rows.Count > 0);
 }
Пример #4
0
 protected void btnDelete_Click1(object sender, EventArgs e)
 {
     var rep = new CoachRepository(new CSBCDbContext());
     rep.DeleteById(Convert.ToInt32(lblCoachId.Value));
     ClearFields();
     lblCoachId.Value = "";
     LoadCoaches();
     LoadVolunteers();
 }
Пример #5
0
        public void GetCoachVolunteerTest()
        {
            var context = new Core.Data.CSBCDbContext();
            var testinit = new CSBCDbInitializer();
            var rep = new CoachRepository(context);
            var coaches = rep.GetCoachVolunteers(1, testinit.CurrentSeason.SeasonID);

            Assert.IsTrue(coaches.Count<vw_Coaches>() > 0);
        }
        public void UpdateCoach()
        {
            Console.WriteLine("Enter Coach id:");
            string coachId = Console.ReadLine();
            int    tryint;

            while (!int.TryParse(coachId, out tryint))
            {
                Console.WriteLine("Incorrect id! Try again ");
                coachId = Console.ReadLine();
            }

            Console.Write("Enter Coach name:");
            string newName = Console.ReadLine();

            while (!IsAllAlphabetic(newName))
            {
                Console.WriteLine("Incorrect Name! Try again");
                newName = Console.ReadLine();
            }

            Console.Write("Enter Coach surname:");
            string newSurname = Console.ReadLine();

            while (!IsAllAlphabetic(newSurname))
            {
                Console.WriteLine("Incorrect Surname! Try again");
                newSurname = Console.ReadLine();
            }

            Console.Write("Enter Coach work experience:");
            string newWorkExperience = Console.ReadLine();

            while ((!int.TryParse(newWorkExperience, out tryint)) || (!WorkExperienceValidationAttribute.IsValidCoachExperience(Convert.ToInt32(newWorkExperience))))
            {
                Console.WriteLine("Incorrect Work Experience! Try again ");
                newWorkExperience = Console.ReadLine();
            }

            try
            {
                Coach coach = new Coach {
                    FirstName = newName, LastName = newSurname, WorkExperience = Convert.ToInt32(newWorkExperience)
                };
                using (swimmingContext swimdb = new swimmingContext())
                {
                    ICoachManager <Coach> coachManager = new CoachRepository(swimdb);
                    coachManager.Update(Convert.ToInt32(coachId), coach);
                    Console.WriteLine("Coach is updated");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public Coach Get(int id)
 {
     TBL_COACH _coach = new CoachRepository().GetById(id);
     aspnet_Users user = new UsersRepository().GetAll().Where(u => u.UserId == _coach.UserID).SingleOrDefault();
     aspnet_Membership member = new MembershipRepository().GetAll().Where(m => m.UserId == _coach.UserID).SingleOrDefault();
     TBL_REGION _region = new RegionRepository().GetById(_coach.RegionID);
     Coach coach = new Coach();
     coach.UserName = user.UserName;
     coach.RegionName = _region.Name;
     coach.Email = member.Email;
     CoachMappings.ModelToViewModel(coach, _coach);
     return coach;
 }
Пример #8
0
        public void Initialize()
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            _options = new DbContextOptionsBuilder <SportschoolVanDrunenDbContext>()
                       .UseSqlite(_connection)
                       .Options;

            using (var c = new SportschoolVanDrunenDbContext(_options))
            {
                c.Database.EnsureCreated();
            }

            _sut = new CoachRepository(new SportschoolVanDrunenDbContext(_options));
        }
Пример #9
0
        public void CreateCoachTest()
        {
            var context = new Core.Data.CSBCDbContext();

            var rep = new CoachRepository(context);
            Debug.Assert(context.People != null, "context.People != null");
            var coach = new Coach
            {
                CompanyID = 1,
                PeopleID = context.People.FirstOrDefault().PeopleID,
                SeasonID = context.Seasons.First(s => s.CurrentSeason == true).SeasonID,
                CoachPhone = "999-000-9090"
            };
            var i = rep.Insert(coach);

            Assert.IsTrue(coach.CoachID > 0);
        }
        public Coach PostCoach(Coach coach)
        {
            MembershipUser user;
            CoachRepository repository;
            TBL_COACH coachToSave;
            try
            {
                repository = new CoachRepository();
                if (coach.ID > 0)
                {
                    coachToSave = repository.GetById(coach.ID);
                    coachToSave.LastUpdatedBy = new Guid(coach.CreatedByCorporateID);
                    coachToSave.LastCreatedDate = DateTime.Now;

                    CoachMappings.ViewModelToModel(coachToSave, coach);

                    repository.Update(coachToSave);
                    user = Membership.GetUser(coachToSave.UserID);
                    user.Email = coach.Email;
                    Membership.UpdateUser(user);
                }
                else
                {
                    user = Membership.CreateUser(coach.UserName, "pa$$word", coach.Email);
                    Roles.AddUserToRole(coach.UserName, SandlerRoles.Coach.ToString());

                    coachToSave = new TBL_COACH();
                    coachToSave.CreatedBy = new Guid(coach.CreatedByCorporateID);
                    coachToSave.UserID = (Guid)user.ProviderUserKey;
                    coachToSave.CreatedDate = DateTime.Now;
                    coachToSave.LastCreatedDate = DateTime.Now;
                    coachToSave.IsActive = true;
                    CoachMappings.ViewModelToModel(coachToSave, coach);
                    repository.Add(coachToSave);
                    coach.UserName = user.UserName;
                }

                //CoachMappings.ModelToViewModel(coach, coachToSave);
            }
            catch (Exception ex)
            {
            }
            return coach;
        }
        public void SelectCoaches()
        {
            try
            {
                Console.Write("Coaches:\n");
                Console.WriteLine("\tCoach Id \tFirstName \tSecondName\tWorkExperience");

                using (swimmingContext swimdb = new swimmingContext())
                {
                    ICoachManager <Coach> coachManager = new CoachRepository(swimdb);
                    var coaches = coachManager.GetList();
                    foreach (Coach c in coaches)
                    {
                        Console.WriteLine($"{c.Id,15}{c.FirstName,15} {c.LastName,17} {c.WorkExperience,15}");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #12
0
        protected void cmbAsstCoach_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            lblCAsstPhone.Text = "";
            lblHAsstPhone.Text = "";
            Session["AsstCoachID"] = cmbCoach.SelectedItem.Value;

            var coachId = Convert.ToInt32(cmbAsstCoach.SelectedItem.Value);
            if (!(String.IsNullOrEmpty((string)Session["AsstCoachID"])))
            {
                var rep = new CoachRepository(new CSBCDbContext());
                var coach = rep.GetCoach(coachId);
                try
                {
                    if (coach != null)
                    {
                        if (coach.CoachPhone.Length > 0)
                            lblHAsstPhone.Text = "(H) " + coach.CoachPhone;
                        else
                            lblHAsstPhone.Text = "";
                        if (coach.Cellphone.Length > 0)
                            lblCAsstPhone.Text = "(C) " + coach.Cellphone;
                        else
                            lblCAsstPhone.Text = "";

                    }
                }
                catch (Exception ex)
                {
                    lblError.Text = "cmbAsstCoach::" + ex.Message;
                }
            }
        }
        private IEnumerable<TBL_OPPORTUNITIES> Getopportunities(UserModel user)
        {
            OpportunitiesRepository opportunitiesSource = new OpportunitiesRepository();
            IEnumerable<TBL_OPPORTUNITIES> opportunties = null;
            try
            {
                if (user.Role == SandlerRoles.FranchiseeUser)
                    opportunties = opportunitiesSource.GetAll().Where(record => record.IsActive == true && record.CreatedBy.ToLower() == user.UserId.ToString().ToLower()).AsEnumerable();
                else if (user.Role == SandlerRoles.FranchiseeOwner)
                {
                    //opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true)
                    //               from company in companies.Where(record => record.COMPANIESID == opportunity.COMPANYID)
                    //               select opportunity;
                    opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true && record.TBL_COMPANIES.FranchiseeId == user.FranchiseeID)
                                   select opportunity;
                }
                else if (user.Role == SandlerRoles.Coach)
                {
                    FranchiseeRepository franchiseeSource = new FranchiseeRepository();
                    CoachRepository coachSource = new CoachRepository();
                    //opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true)
                    //               from company in companies.Where(record => record.COMPANIESID == opportunity.COMPANYID)
                    //               from franchisee in franchisees.Where(record => record.ID == company.FranchiseeId)
                    //               select opportunity;
                    opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true && record.TBL_COMPANIES.TBL_FRANCHISEE.CoachID == user.CoachID)
                                   select opportunity;

                }
                else if (user.Role == SandlerRoles.Corporate)
                {
                    opportunties = opportunitiesSource.GetAll().Where(record => record.IsActive == true).AsEnumerable();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("exception in UserEntities.Getopportunities: " + ex.Message);
            }
            return opportunties;
        }
Пример #14
0
        private int Create()
        {
            var rep = new CoachRepository(new CSBCDbContext());
            var coach = new Coach();
            try
            {

                coach.ShirtSize = cmbSizes.Text;
                coach.SeasonID = Master.SeasonId;
                coach.CompanyID = Master.CompanyId;
                coach.CreatedDate = DateTime.Today;
                coach.PeopleID = Convert.ToInt32(cmbCoaches.SelectedValue);
                if (txtCoachPhone.Text != "")
                {
                    coach.CoachPhone = txtCoachPhone.Text;
                }
                else
                {
                    coach.CoachPhone = "";
                }
                coach.CreatedUser = Session["UserName"].ToString();
                rep.Insert(coach);
                CoachId = (int)coach.CoachID;
                Session["coachId"] = CoachId;
            }
            catch (Exception ex)
            {
                Session["ErrorMSG"] = ex.Message;
            }
            return CoachId;
        }
Пример #15
0
        public void GetSeasonCoachesTest()
        {
            var context = new Core.Data.CSBCDbContext();
            var testinit = new CSBCDbInitializer();
            var rep = new CoachRepository(context);
            var coaches = rep.GetSeasonCoaches(testinit.CurrentSeason.SeasonID);

            Assert.IsTrue(coaches.Any<vw_Coaches>() );
        }
Пример #16
0
        private void LoadCoach(int coachId)
        {
            using (var db = new CSBCDbContext())
            {
                var rep = new CoachRepository(db);
                cmbCoaches.Visible = false;

                var coach = rep.GetById(coachId);
                CoachId = coach.CoachID;
                Master.PeopleId = coach.PeopleID;
                lblCoachId.Value = CoachId.ToString();
                if (coach.Person != null)
                {
                    lnkName.Text = coach.Person.FirstName + " " + coach.Person.LastName;
                    if (coach.Person.Household != null)
                    {
                        lblAddress.Text = coach.Person.Household.Address1;
                        lblPhone.Text = coach.Person.Household.Phone;
                        lblCSZ.Text = coach.Person.Household.City + ", " + coach.Person.Household.State + " " + coach.Person.Household.Zip;
                    }
                }

                txtCoachPhone.Text = coach.CoachPhone;
                cmbSizes.SelectedValue = coach.ShirtSize;
            }
            pnlCoach.Visible = true;
            GetKids(coachId);
        }
Пример #17
0
        private void LoadCoaches()
        {
            var rep = new CoachRepository(new CSBCDbContext());
            try
            {
                var rsData = rep.GetSeasonCoaches(Master.SeasonId);

                //grdCoaches.Columns.Clear();
                if (rsData.Count<vw_Coaches>() > 0)
                {
                    var _with1 = grd;
                    grd.DataSource = rsData;
                    grd.DataBind();

                }
            }
            catch (Exception ex)
            {
                lblError.Text = "LoadCoaches::" + ex.Message;
            }
        }
Пример #18
0
        private void LoadVolunteers()
        {
            var rep = new CoachRepository(new CSBCDbContext());

            try
            {
                var coaches = rep.GetCoachVolunteers(Master.CompanyId, Master.SeasonId);
                vw_Coaches coach = new vw_Coaches { PeopleID = 0, Name = "" };

                cmbCoaches.DataSource = coaches;
                cmbCoaches.DataValueField = "PeopleID";
                cmbCoaches.DataTextField = "Name";
                cmbCoaches.DataBind();
                cmbCoaches.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                cmbCoaches.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                lblError.Text = "LoadVolunteers::" + ex.Message;
            }
        }
Пример #19
0
 public void UpdateCoachesTest()
 {
     var context = new Core.Data.CSBCDbContext();
     var testinit = new CSBCDbInitializer();
     var rep = new CoachRepository(context);
     var coach = context.Coaches.FirstOrDefault();
     coach.ShirtSize = shirtSize;
     coach.CoachPhone = coachPhone;
     rep.Update(coach);
     var newcoach = rep.GetById(coach.CoachID);
     Assert.IsTrue(newcoach.ShirtSize == shirtSize);
     Assert.IsTrue(newcoach.CoachPhone == coachPhone);
 }
Пример #20
0
        private void UpdateCoachPhone()
        {
            if (cmbCoach.SelectedItem.Value != "")
            {
                Session["CoachID"] = cmbCoach.SelectedItem.Value;
                var coachId = Convert.ToInt32(cmbCoach.SelectedItem.Value);
                if (!(String.IsNullOrEmpty((string)Session["CoachID"])))
                {
                    var rep = new CoachRepository(new CSBCDbContext());
                    var coach = rep.GetCoach(coachId);
                    try
                    {
                        if (coach != null)
                        {
                            if (coach.CoachPhone.Length > 0)
                                lblCHPhone.Text = "(H) " + coach.CoachPhone;
                            else
                                lblCHPhone.Text = "";
                            if (coach.Cellphone.Length > 0)
                                lblCCPhone.Text = "(C) " + coach.Cellphone;
                            else
                                lblCHPhone.Text = "";

                        }
                    }
                    catch (Exception ex)
                    {
                        lblError.Text = "cmbCoach::" + ex.Message;
                    }
                }
            }
        }
Пример #21
0
        private void LoadCoaches()
        {
            try
            {
                using (var db = new CSBCDbContext())
                {
                    var rep = new CoachRepository(db);
                    var rsData = rep.GetSeasonCoaches(Master.SeasonId);
                    cmbCoach.DataSource = rsData;
                    cmbCoach.DataValueField = "CoachID";
                    cmbCoach.DataTextField = "Name";
                    cmbCoach.DataBind();
                    cmbCoach.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                    cmbCoach.SelectedIndex = 0;

                    cmbAsstCoach.DataSource = rsData;
                    cmbAsstCoach.DataValueField = "CoachID";
                    cmbAsstCoach.DataTextField = "Name";
                    cmbAsstCoach.DataBind();
                    cmbAsstCoach.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                    cmbAsstCoach.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = "LoadCoaches::" + ex.Message;
            }
        }
Пример #22
0
        private int Update()
        {
            var rep = new CoachRepository(new CSBCDbContext());
            if (CoachId != 0)
            {
                //var id = Convert.ToInt32(lblCoachId.Value);
                var coach = rep.GetCoachForSeason(Master.SeasonId, Master.PeopleId); //change this logic to only have one call
                if (coach == null)
                {
                    Create();
                }
                else
                {
                    try
                    {
                        coach.ShirtSize = cmbSizes.Text;
                        if (txtCoachPhone.Text != "")
                        {
                            coach.CoachPhone = txtCoachPhone.Text;
                        }
                        else
                        {
                            coach.CoachPhone = "";
                        }
                        rep.Update(coach);

                    }
                    catch
                    {
                    }
                }
            }
            else
            {

            }
            return (CoachId);
        }