/*
  Depending on the value in the session we prepopulate the employee data.
  */
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["UserId"] != null)
     {
         if (!IsPostBack)
         {
             /*
              We Fetch the UserId from session and populate the data from UserAccount Table
              */
             int _userID = Convert.ToInt32(Session["UserId"]);
             PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
             var _query = (from userAccount in _dataContext.UserAccounts
                           where
                               userAccount.UserAccountID_in.Equals(_userID)
                           select userAccount).FirstOrDefault();
             FirstName.Text = _query.FirstName_vc;
             LastName.Text = _query.LastName_vc;
             Address.Text = _query.Address_vc;
             PhoneNumber.Text = _query.PhoneNumber_vc;
             Email.Text = _query.EmailId_vc;
             DateTime _dateTime = Convert.ToDateTime(_query.DOB_date);
             DateOfBirthOne.Text = _dateTime.Date.ToString("d");
             Session["ProfileId"] = _query.UserAccountID_in;
         }
     }
     else
     {
         Response.Redirect("/Account/InvalidLogin");
     }
 }
 /*
  OnClick Event to handle Delete Button in Grid
  */
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     /*
      Depending on the value in the session we delete the particular Slot and update the Bill Amount
      */
     var _userId = Convert.ToInt32(Session["UserId"]);
     PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
     var _slotInformationId = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[7].Text.Trim());
     var _slotId = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[6].Text.Trim());
     var _member = (from member in _dataContext.Members where member.FK_UserAccount_Member_in.Equals(_userId) select member).FirstOrDefault();
     var _deleteQuery = (from slotInformation in _dataContext.SlotInformations where slotInformation.SlotInformationID_in.Equals(_slotInformationId) select slotInformation).FirstOrDefault();
     var _updateQuery = (from slot in _dataContext.Slots where slot.SlotID_in.Equals(_slotId) select slot).FirstOrDefault();
     _updateQuery.AvailableSlots_in = _updateQuery.AvailableSlots_in + 1;
     _member.BillAmount_de = _member.BillAmount_de - Decimal.Parse("20.55");
     try
     {
         _dataContext.SlotInformations.DeleteOnSubmit(_deleteQuery);
         _dataContext.SubmitChanges();
         Response.Redirect("/Member/BookingInformation?bookingStatus=false");
     }
     catch (Exception exception)
     {
         ErrorMessage.Text = "Something went wrong..Please try again.";
         Console.WriteLine(exception);
     }
 }
 /*
  On Click Event for the Edit Employee Button Click
  */
 protected void EditEmployeeProfile_Click(object sender, EventArgs e)
 {
     if (IsValid)
     {
         /*
          Depending on the UserId we update the value in the UserAccount Table
          */
         PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
         String _userAccountId = Session["ProfileId"].ToString();
         var _userAccount = (from userAccountData in _dataContext.UserAccounts
                             where userAccountData.UserAccountID_in.Equals(_userAccountId)
                             select userAccountData).FirstOrDefault();
         _userAccount.FirstName_vc = FirstName.Text;
         _userAccount.LastName_vc = LastName.Text;
         _userAccount.Address_vc = Address.Text;
         _userAccount.PhoneNumber_vc = PhoneNumber.Text;
         _userAccount.EmailId_vc = Email.Text;
         _userAccount.DOB_date = Convert.ToDateTime(DateOfBirthOne.Text);
         try
         {
             _dataContext.SubmitChanges();
             Response.Redirect("/Employee/EmployeeProfile?editProfile=true");
         }
         catch (Exception exception)
         {
             ErrorMessage.Text = "Something went wrong..Please try again.";
             Console.WriteLine(exception);
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
             Depending on the value in the Session we fetch the slot that he has reserved
             */
            if (Session["UserId"] != null)
            {
                var _userId = Convert.ToInt32(Session["UserId"]);
                /*
                 If the Query String Contains a value then we display a success message
                 */
                if (Request.QueryString["bookingStatus"] != null)
                {
                    var _bookingStatus = Request.QueryString["bookingStatus"].ToString().Trim();
                    if (_bookingStatus == "true")
                    {
                        SuccessMessage.Text = "Slot Booking Successful";
                    }
                    else if (_bookingStatus == "false")
                    {
                        SuccessMessage.Text = "Slot Deleted Successful";
                    }
                }
                /*
                 We fetch the values form the USerAccount, Activity and Slot Information Tables
                 */
                PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
                var _member = (from member in _dataContext.Members where member.FK_UserAccount_Member_in.Equals(_userId) select member).FirstOrDefault();
                var _query = (from slotInformation in _dataContext.SlotInformations
                              join slot in _dataContext.Slots
                              on slotInformation.FK_Slot_SlotInformation_in
                              equals slot.SlotID_in
                              where slotInformation.FK_Member_SlotInformation_in.Equals(_member.MemberID_in)
                              select new
                              {
                                  UserName = (from userAccount in _dataContext.UserAccounts
                                              where userAccount.UserAccountID_in.Equals(slotInformation.FK_Member_SlotInformation_in)
                                              select userAccount).FirstOrDefault().UserName_vc,
                                  Acivity = (from activity in _dataContext.Activities
                                             where activity.ActivityID_in.Equals(slotInformation.FK_Activity_SlotInformation_in)
                                             select activity).FirstOrDefault().Activity_vc,
                                  StartTime = slot.StartTime_vc,
                                  EndTime = slot.EndTime_vc,
                                  Trainer = (from userAccount in _dataContext.UserAccounts
                                             join trainer in _dataContext.Trainers on
                                             userAccount.UserAccountID_in equals trainer.FK_UserAccount_Trainer_in
                                             where trainer.TrainerID_in.Equals(slot.FK_Trainer_Slot_in)
                                             select new { userAccount.UserName_vc }).FirstOrDefault().UserName_vc,
                                  SlotId = slot.SlotID_in,
                                  SlotInformationId = slotInformation.SlotInformationID_in
                              });

                GridView1.DataSource = _query;
                GridView1.DataBind();
            }
            else
            {
                Response.Redirect("/Account/InvalidLogin");
            }
        }
Example #5
0
 /*
  On Change Event where we populate the Trainer List on the type of Activity Selected
  */
 protected void Activity_SelectedIndexChanged(object sender, EventArgs e)
 {
     var _value = Activity.SelectedValue;
     /*
      If a Empty value is selected after valid value was present
      */
     if (_value.Equals(""))
     {
         ErrorMessage.Text = "Select a valid Activity";
     }
     /*
      If value entered is valid, then fetch the trainer corresponding to Activity
      */
     else
     {
         PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
         var _trainerNames = (from userAccount in _dataContext.UserAccounts
                              join trainer in _dataContext.Trainers on
                              userAccount.UserAccountID_in equals trainer.FK_UserAccount_Trainer_in
                              where trainer.FK_Activity_Trainer_in.Equals(_value)
                              select new
                              {
                                  UserName = userAccount.UserName_vc,
                                  UserAccountId = userAccount.UserAccountID_in
                              });
         Trainer.DataSource = _trainerNames;
         Trainer.DataTextField = "UserName";
         Trainer.DataValueField = "UserAccountId";
         Trainer.DataBind();
         Trainer.Items.Insert(0, new ListItem("--Select--", ""));
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     /*
      Depending on the UserId we populate the Slots that the Trainer has to train
      */
     if (Session["UserId"] != null)
     {
         var _userId = Convert.ToInt32(Session["UserId"]);
         PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
         var _query = (from slot in _dataContext.Slots
                       where slot.FK_Trainer_Slot_in.Equals
                           ((from trainer in _dataContext.Trainers
                             where trainer.FK_UserAccount_Trainer_in.Equals(_userId)
                             select trainer).FirstOrDefault().TrainerID_in)
                       select new
                       {
                           SlotId = slot.SlotID_in,
                           ActivityId = (from activity in _dataContext.Activities where activity.ActivityID_in.Equals(slot.FK_Activity_Slot_in) select activity).FirstOrDefault().Activity_vc,
                           StartTime = slot.StartTime_vc,
                           EndTime = slot.EndTime_vc,
                           BookedSlots = slot.NumberOfSlots_in - slot.AvailableSlots_in
                       });
         GridView1.DataSource = _query;
         GridView1.DataBind();
     }
     else
         Response.Redirect("/Account/InvalidLogin");
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
             If the Query String contains the WCF USer that is the page is being redirected from HMS
             */
            if(Request.QueryString["WCFUser"]!= null)
            {
                Session["UserId"] = Request.QueryString["WCFUser"].ToString();
            }
            if (Session["UserId"] != null)
            {
                int _userID = Convert.ToInt32(Session["UserId"]);

                PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
                /*
                 If we get the Query String we display an success message for successful updation of the profile.
                 */
                if (Request.QueryString["editProfile"] != null)
                {
                    var _bookingStatus = Request.QueryString["editProfile"].ToString().Trim();
                        if (_bookingStatus == "true")
                        {
                            SuccessMessage.Text = "Profile Updated Successfully";
                        }
                }
                var _row = (from userAccount in _dataContext.UserAccounts
                           where
                               userAccount.UserAccountID_in.Equals(_userID)
                           select userAccount);
                if (_row.Count() == 1)
                {
                    DataTable _dataTable = new DataTable();
                    _dataTable.Columns.Add("Attribute", typeof(string));
                    _dataTable.Columns.Add("Value", typeof(string));
                    _dataTable.Rows.Add("First Name", _row.FirstOrDefault().FirstName_vc);
                    _dataTable.Rows.Add("Last Name", _row.FirstOrDefault().LastName_vc);
                    _dataTable.Rows.Add("User Name", _row.FirstOrDefault().UserName_vc);
                    _dataTable.Rows.Add("Address", _row.FirstOrDefault().Address_vc);
                    _dataTable.Rows.Add("Phone Number", _row.FirstOrDefault().PhoneNumber_vc);
                    _dataTable.Rows.Add("Email Id", _row.FirstOrDefault().EmailId_vc);
                    DateTime _dateTime = Convert.ToDateTime(_row.FirstOrDefault().DOB_date);
                    _dataTable.Rows.Add("Date Of Birth", _dateTime.Date.ToString("d"));
                    gridView1.DataSource = _dataTable;
                    gridView1.DataBind();
                }
            }
            else
                Response.Redirect("/Account/InvalidLogin");
        }
Example #8
0
        /*
         If we get a Query String then we display a success message indicating successful updation
         */
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserId"] != null)
            {
                PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
                if (Request.QueryString["editSlot"] != null)
                {
                    var _bookingStatus = Request.QueryString["editSlot"].ToString().Trim();
                    if (_bookingStatus == "true")
                    {
                        SuccessMessage.Text = "Slot Edited Successful";
                    }
                }
                /*
                 We Populate the Grid with the Slots from the Slots Table
                 */
                var _query = (from slot in _dataContext.Slots
                              join
                                  trainer in _dataContext.Trainers
                                  on slot.FK_Trainer_Slot_in equals trainer.TrainerID_in
                              join userAccount in _dataContext.UserAccounts
                              on trainer.FK_UserAccount_Trainer_in equals userAccount.UserAccountID_in
                              select new
                              {
                                  SlotId = slot.SlotID_in,
                                  ActivityName = (from activity in _dataContext.Activities
                                                  where activity.ActivityID_in.Equals(slot.FK_Activity_Slot_in)
                                                  select activity).FirstOrDefault().Activity_vc,
                                  StartTime = slot.StartTime_vc,
                                  EndTime = slot.EndTime_vc,
                                  NumberOfSlots = slot.NumberOfSlots_in,
                                  AvailableSlots = slot.AvailableSlots_in,
                                  UserName = userAccount.UserName_vc
                              });

                GridView1.DataSource = _query;
                GridView1.DataBind();
            }
            else
            {
                Response.Redirect("/Account/InvalidLogin");
            }
        }
 /*
  We are to fetch values of all employees who are Trainers
  */
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["UserId"] != null)
     {
         PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
         var _query = (from userAccount in _dataContext.UserAccounts
                      join userTypes in _dataContext.UserTypes on
                      userAccount.FK_UserType_UserAccount_in equals userTypes.UserTypeID_in
                      where userTypes.UserType_vc.Equals("Trainer")
                      select new {FirstName = userAccount.FirstName_vc,
                                 LastName = userAccount.LastName_vc,
                                 EmailId = userAccount.EmailId_vc});
         GridView1.DataSource = _query;
         GridView1.DataBind();
     }
     else
     {
         Response.Redirect("/Account/InvalidLogin");
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     /*
      If not postback Call then preload the Activity list from Activity Table
      */
     if (Session["UserId"] != null)
     {
         if (!IsPostBack)
         {
             PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
             var _query = (from activity in _dataContext.Activities select activity);
             DropDownList1.DataSource = _query;
             DropDownList1.DataTextField = "Activity_vc";
             DropDownList1.DataValueField = "ActivityID_in";
             DropDownList1.DataBind();
             DropDownList1.Items.Insert(0, new ListItem("--Select--", ""));
         }
     }
     else
         Response.Redirect("/Account/InvalidLogin");
 }
 /*
  On Change Event for the Activity List
  */
 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
 {
     /*
      Check if the selected value is valid
      */
     PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
     if (DropDownList1.SelectedValue != "")
     {
         /*
         Depending on the Activity selected populate the Grid with slot values and make it visible
          */
         var _activityId = DropDownList1.SelectedValue;
         var _query = (from slot in _dataContext.Slots
                       where slot.FK_Activity_Slot_in.Equals(_activityId)
                       select new
                       {
                           SlotId = slot.SlotID_in,
                           Activity = (from activity in _dataContext.Activities
                                       where activity.ActivityID_in.Equals(_activityId)
                                       select activity).FirstOrDefault().Activity_vc,
                           StartTime = slot.StartTime_vc,
                           EndTime = slot.EndTime_vc,
                           Trainer = (from userAccount in _dataContext.UserAccounts
                                      join trainer in _dataContext.Trainers on
                                      userAccount.UserAccountID_in equals trainer.FK_UserAccount_Trainer_in
                                      where trainer.TrainerID_in.Equals(slot.FK_Trainer_Slot_in)
                                      select new { userAccount.UserName_vc }).FirstOrDefault().UserName_vc
                       });
         GridView1.Visible = true;
         GridView1.DataSource = _query;
         GridView1.DataBind();
     }
     else
     {
         GridView1.Visible = false;
     }
 }
        /*
         On Click Event for Edit Slot Button
         */
        protected void EditSlot_Click(object sender, EventArgs e)
        {
            /*
             Only if the form is validated and is valid
             */
            if (IsValid)
            {
                PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
                var _startTime = StartTime.Text;
                var _endTime = EndTime.Text;
                var _slotId = SlotId.Text;
                var _flag = false;
                var _query = (from slots in _dataContext.Slots where slots.SlotID_in.Equals(_slotId) select slots).FirstOrDefault();
                var _slotInformation = (from slotInformation in _dataContext.SlotInformations where slotInformation.FK_Slot_SlotInformation_in.Equals(_slotId) select slotInformation);
                /*
                 If slot being changed is booke dalready it cannot be changed
                 */
                if (Convert.ToInt32(_startTime) < Convert.ToInt32(_endTime))
                {
                    if (_slotInformation.Count() != 0)
                    {
                        ErrorMessage.Text = "Slot has already been booked cannot change the slot";
                    }
                    /*
                     Check if the time values entered is between 8 A.M and 8 P.M
                     */
                    else
                    {
                        if ((Convert.ToInt32(_startTime) < 8) || (Convert.ToInt32(_startTime) > 20))
                            ErrorMessage.Text = "Start Time should be between 8 A.M and 8 P.M";
                        else if ((Convert.ToInt32(_endTime) < 8) || (Convert.ToInt32(_endTime) > 20))
                            ErrorMessage.Text = "End Time should be between 8 A.M and 8 P.M";
                        else if ((Convert.ToInt32(_startTime) - Convert.ToInt32(_endTime)) >= 0)
                            ErrorMessage.Text = "End Time should be greater than Start Time";
                        /*
                         * Convert time to 12 hours format and add A.M or P.M
                         */
                        else
                        {
                            if (Convert.ToInt32(_startTime) > 8 && Convert.ToInt32(_startTime) < 12)
                            {
                                _startTime = _startTime + " A.M";
                                _flag = true;
                            }
                            else if (Convert.ToInt32(_startTime) >= 12 && Convert.ToInt32(_startTime) <= 20)
                            {
                                if (Convert.ToInt32(_startTime) != 12)
                                    _startTime = (Convert.ToInt32(_startTime) - 12).ToString();
                                _startTime = _startTime + " P.M";
                                _flag = true;
                            }
                            if (Convert.ToInt32(_endTime) > 8 && Convert.ToInt32(_endTime) < 12)
                            {
                                _endTime = _endTime + " A.M";
                                _flag = true;
                            }
                            else if (Convert.ToInt32(_endTime) >= 12 && Convert.ToInt32(_endTime) <= 20)
                            {
                                if (Convert.ToInt32(_endTime) != 12)
                                    _endTime = (Convert.ToInt32(_endTime) - 12).ToString();
                                _endTime = _endTime + " P.M";
                                _flag = true;
                            }
                            /*
                             If all the values are valid then update the slot
                             */
                            if (_flag)
                            {
                                _query.AvailableSlots_in = Convert.ToInt32(Availability.Text);
                                _query.StartTime_vc = _startTime;
                                _query.EndTime_vc = _endTime;
                                _query.NumberOfSlots_in = Convert.ToInt32(Availability.Text);
                                _query.FK_Trainer_Slot_in = Convert.ToInt32(Trainer.SelectedValue);
                                try
                                {
                                    _dataContext.SubmitChanges();
                                    Response.Redirect("/Employee/EditSlot?editSlot=true");
                                }
                                catch (Exception exception)
                                {
                                    ErrorMessage.Text = "Something went wrong..Please try again.";
                                    Console.WriteLine(exception);
                                }
                            }

                        }
                    }
                }
                else
                {
                    ErrorMessage.Text = "Start Time should be greater than End Time";
                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     /*
      Only if it is not postback call then we prepopulate the fields with the Slot Information from slot Table
      */
     if (Session["UserId"] != null)
     {
         if (!IsPostBack)
         {
             if (Request.QueryString["slotId"] != null)
             {
                 var _slotId = Request.QueryString["slotId"].ToString().Trim();
                 PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
                 var _query = (from slots in _dataContext.Slots where slots.SlotID_in.Equals(_slotId) select slots).FirstOrDefault();
                 var _activities = (from activity in _dataContext.Activities select activity);
                 /*
                  Activity List is populated and Corresponding activity is selected
                  */
                 Activity.DataSource = _activities;
                 Activity.DataTextField = "Activity_vc";
                 Activity.DataValueField = "ActivityID_in";
                 Activity.DataBind();
                 Activity.Items.Insert(0, new ListItem("--Select--", ""));
                 Activity.Items.FindByValue(_query.FK_Activity_Slot_in.ToString()).Selected = true;
                 Availability.Text = _query.NumberOfSlots_in.ToString();
                 StartTime.Text = _query.StartTime_vc.Substring(0, (_query.StartTime_vc.IndexOf(' ')));
                 EndTime.Text = _query.EndTime_vc.Substring(0, (_query.EndTime_vc.IndexOf(' ')));
                 SlotId.Text = _slotId;
                 var _trainerNames = (from userAccount in _dataContext.UserAccounts
                                      join trainer in _dataContext.Trainers on
                                      userAccount.UserAccountID_in equals trainer.FK_UserAccount_Trainer_in
                                      where trainer.FK_Activity_Trainer_in.Equals(_query.FK_Activity_Slot_in)
                                      select new
                                      {
                                          UserName = userAccount.UserName_vc,
                                          TrainerId = trainer.TrainerID_in
                                      });
                 /*
                  Trainer List is populated and Corresponding Trainer is selected
                  */
                 Trainer.DataSource = _trainerNames;
                 Trainer.DataTextField = "UserName";
                 Trainer.DataValueField = "TrainerId";
                 Trainer.DataBind();
                 Trainer.Items.Insert(0, new ListItem("--Select--", ""));
                 Trainer.Items.FindByValue(_query.FK_Trainer_Slot_in.ToString()).Selected = true;
             }
         }
     }
     else
     {
         Response.Redirect("/Account/InvalidLogin");
     }
 }
 /*
  On selecting a Radio Button we Book the Slot
  */
 protected void RowSelector_CheckedChanged(object sender, EventArgs e)
 {
     for (int i = 0; i < GridView1.Rows.Count; i++)
     {
         RadioButton rb = (RadioButton)(GridView1.Rows[i].Cells[0].FindControl("radioButton1"));
         /*
          We Check among all the Grid Rows which is checked
          */
         if (rb.Checked == true)
         {
             /*
              We fetch the values from the Grid and insert in the SlotInformation Table and update slot Table
              */
             var _slotId = GridView1.Rows[i].Cells[1].Text;
             var _trainerName = GridView1.Rows[i].Cells[5].Text.Trim();
             var _acivityName = GridView1.Rows[i].Cells[2].Text.Trim();
             rb.Checked = false;
             PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
             UserAccount _userAccount = new UserAccount();
             SlotInformation slotInformation = new SlotInformation();
             Trainer trainer = new Trainer();
             int _userID = Convert.ToInt32(Session["UserId"]);
             var _member = (from member in _dataContext.Members where member.FK_UserAccount_Member_in.Equals(_userID) select member).FirstOrDefault();
             var _query = (from user in _dataContext.UserAccounts where user.UserName_vc.Equals(_trainerName) select user).FirstOrDefault().UserAccountID_in;
             var _queryActivity = (from activity in _dataContext.Activities where activity.Activity_vc.Equals(_acivityName) select activity).FirstOrDefault().ActivityID_in;
             var _querySlot = (from slot in _dataContext.Slots where slot.SlotID_in.Equals(_slotId) select slot).FirstOrDefault();
             _querySlot.AvailableSlots_in = _querySlot.AvailableSlots_in - 1;
             _member.BillAmount_de = _member.BillAmount_de + Decimal.Parse("20.55");
             slotInformation.FK_Slot_SlotInformation_in = Convert.ToInt32(_slotId);
             slotInformation.FK_Member_SlotInformation_in = _member.MemberID_in;
             slotInformation.FK_Activity_SlotInformation_in = _queryActivity;
             try
             {
                 _dataContext.SlotInformations.InsertOnSubmit(slotInformation);
                 _dataContext.SubmitChanges();
                 Response.Redirect("/Member/BookingInformation?bookingStatus=true");
             }
             catch (Exception exception)
             {
                 ErrorMessage.Text = "Something went wrong..Please try again.";
                 Console.WriteLine(exception.InnerException);
             }
         }
     }
 }
Example #15
0
 /*
  On Click Event when a Add Slot Button is Clicked
  */
 protected void AddSlot_Click(object sender, EventArgs e)
 {
     /*
      Only if the form is validated and is valid then perform some action
      */
     if (IsValid)
     {
         /*
          Get Start and End Time with out Minutes
          */
         var _startTime = StartTime.Text.Split(':')[0];
         var _endTime = EndTime.Text.Split(':')[0];
         var _flag = false;
         if (_startTime.IndexOf('0') == 0)
             _startTime = _startTime.Substring(1);
         else if (_endTime.IndexOf('0') == 0)
             _endTime = _endTime.Substring(1);
         /*
          verify the Time is between 8 A.M and 8 P.M
          */
         if ((Convert.ToInt32(_startTime) < 8) || (Convert.ToInt32(_startTime) > 20))
             ErrorMessage.Text = "Start Time should be between 8 A.M and 8 P.M";
         else if ((Convert.ToInt32(_endTime) < 8) || (Convert.ToInt32(_endTime) > 20))
             ErrorMessage.Text = "End Time should be between 8 A.M and 8 P.M";
         else if ((Convert.ToInt32(_startTime) - Convert.ToInt32(_endTime)) >= 0)
             ErrorMessage.Text = "End Time should be greater than Start Time";
         /*
          Convert the time to 12 hours format and flag if it is valid
          */
         else
         {
             if (Convert.ToInt32(_startTime) > 8 && Convert.ToInt32(_startTime) < 12)
             {
                 _startTime = _startTime + " A.M";
                 _flag = true;
             }
             else if (Convert.ToInt32(_startTime) >= 12 && Convert.ToInt32(_startTime) <= 20)
             {
                 if (Convert.ToInt32(_startTime) != 12)
                     _startTime = (Convert.ToInt32(_startTime) - 12).ToString();
                 _startTime = _startTime + " P.M";
                 _flag = true;
             }
             if (Convert.ToInt32(_endTime) > 8 && Convert.ToInt32(_endTime) < 12)
             {
                 _endTime = _endTime + " A.M";
                 _flag = true;
             }
             else if (Convert.ToInt32(_endTime) >= 12 && Convert.ToInt32(_endTime) <= 20)
             {
                 if (Convert.ToInt32(_endTime) != 12)
                     _endTime = (Convert.ToInt32(_endTime) - 12).ToString();
                 _endTime = _endTime + " P.M";
                 _flag = true;
             }
         }
         /*
           If a Valid Activity adnd Trainer are selected
          */
         if (Activity.SelectedValue != "" && Trainer.SelectedValue != "")
         {
             /*
              And if time is valid Then insert the values to Database
              */
             if (_flag)
             {
                 PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
                 Slot _slot = new Slot();
                 _slot.NumberOfSlots_in = Convert.ToInt32(Availability.Text);
                 _slot.AvailableSlots_in = Convert.ToInt32(Availability.Text);
                 _slot.FK_Activity_Slot_in = Convert.ToInt32(Activity.SelectedValue);
                 _slot.FK_Trainer_Slot_in = (from userAccount in _dataContext.UserAccounts
                                             join trainer in _dataContext.Trainers on
                                             userAccount.UserAccountID_in equals trainer.FK_UserAccount_Trainer_in
                                             where userAccount.UserAccountID_in.Equals(Trainer.SelectedValue)
                                             select trainer).FirstOrDefault().TrainerID_in;
                 _slot.StartTime_vc = _startTime;
                 _slot.EndTime_vc = _endTime;
                 _dataContext.Slots.InsertOnSubmit(_slot);
                 _dataContext.SubmitChanges();
                 Response.Redirect("/Employee/AddSlot?slotAdded=true");
             }
         }
         else
         {
             ErrorMessage.Text = "Select a valid Activity and Trainer";
         }
     }
 }
 /*
  On Click event to Make Payment Button Click
  */
 protected void MakePayment_Click(object sender, EventArgs e)
 {
     /*
      Only Perform some action if form is validated and is valid
      */
     if (IsValid)
     {
         var _expDate = "";
         var _expYear = "";
         decimal _amount = 0;
         /*
          Check for validity of the Year and month Values
          */
         if (ExpiryDate.Text != "")
         {
             if (ExpiryDate.Text.Length == 1)
                 _expDate = '0' + ExpiryDate.Text;
             else
                 _expDate = ExpiryDate.Text;
         }
         if (ExpiryDateYear.Text != "")
         {
             _expYear = ExpiryDateYear.Text.Substring(2, 2);
         }
         /*
          Check for validity of Bill Amount
          */
         try
         {
             _amount = Decimal.Parse(Amount.Text);
         }
         catch (Exception exception)
         {
             ErrorMessage.Text = "Should be a decimal value";
             Console.WriteLine(exception);
         }
         PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
         var _userId = Convert.ToInt32(Session["UserId"]);
         var _validAmount = (from member in _dataContext.Members where member.FK_UserAccount_Member_in.Equals(_userId) select member).FirstOrDefault().BillAmount_de;
         /*
         Check whether Bill Amount is valid that is less than or equal to Actual Bill Amount
         */
         var _compare = Decimal.Compare(_amount, _validAmount);
         label1.Text = _compare.ToString();
         if (_compare > 0)
         {
             ErrorMessage.Text = "Amount should be less than amount to be paid";
         }
         else
         {
             var _query = (from cardDetails in _dataContext.CardDetails
                           where cardDetails.CardNo_in.Equals(CardNumber.Text)
                           && cardDetails.ExpDate_vc.Equals(_expDate + "/" + _expYear)
                           && cardDetails.FK_Member_CardDetails_in.Equals((from member in _dataContext.Members
                                                                           where member.FK_UserAccount_Member_in.
                                                                           Equals(Session["UserId"].ToString())
                                                                           select member).FirstOrDefault().MemberID_in)
                           select cardDetails);
             var _memberDetails = (from member in _dataContext.Members
                                   where member.FK_UserAccount_Member_in.
                                   Equals(Session["UserId"].ToString())
                                   select member).FirstOrDefault();
             if (_query.Count() != 0)
             {
                 _memberDetails.BillAmount_de = Math.Abs(_validAmount - _amount);
                 _dataContext.SubmitChanges();
                 Response.Redirect("/Member/PaymentSuccessful");
             }
             else
             {
                 ErrorMessage.Text = "Card Details Should be Valid";
             }
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     /*
      Depeding on the userId in the session we fetch the Card Details
      */
     if (Session["UserId"] != null)
     {
         if (!IsPostBack)
         {
             PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();
             var _userId = Convert.ToInt32(Session["UserId"]);
             var _query = (from cardDetails in _dataContext.CardDetails
                           where cardDetails.FK_Member_CardDetails_in.Equals((from member in _dataContext.Members
                                                                              where member.FK_UserAccount_Member_in.
                                                                              Equals(Session["UserId"].ToString())
                                                                              select member).FirstOrDefault().MemberID_in)
                           select cardDetails);
             /*
              Populate the list with the values of months
              */
             var _month = Enumerable.Range(1, 12)
                         .Select(i => new { Text = i.ToString(), Value = i.ToString() });
             ExpiryDate.DataSource = _month;
             ExpiryDate.DataTextField = "Text";
             ExpiryDate.DataValueField = "Value";
             ExpiryDate.DataBind();
             ExpiryDate.Items.Insert(0, new ListItem("--Month--", ""));
             /*
              Populate the list with the values of years
              */
             var _year = Enumerable.Range(2010, 32)
                            .Select(i => new { Text = i.ToString(), Value = i.ToString() });
             ExpiryDateYear.DataSource = _year;
             ExpiryDateYear.DataTextField = "Text";
             ExpiryDateYear.DataValueField = "Value";
             ExpiryDateYear.DataBind();
             ExpiryDateYear.Items.Insert(0, new ListItem("--Year--", ""));
             /*
              If there are carddetails in the table for this particular user then prepopulate them
              */
             if (_query.Count() == 1)
             {
                 CardNumber.Text = _query.FirstOrDefault().CardNo_in.ToString();
                 var _date = _query.FirstOrDefault().ExpDate_vc.Split('/')[0];
                 var _monthOf = "20" + _query.FirstOrDefault().ExpDate_vc.Split('/')[1];
                 if (_date.ElementAt(0).Equals('0'))
                     _date = _date.Substring(1, 1);
                 ExpiryDate.SelectedValue = _date;
                 ExpiryDateYear.SelectedValue = _monthOf;
                 SaveCard.Visible = false;
                 SaveCardText.Visible = false;
                 CardHolderName.Text = _query.FirstOrDefault().CardAliasName_vc;
             }
             /*
              Populate the BillAmount
              */
             var _result = (from member in _dataContext.Members where member.FK_UserAccount_Member_in.Equals(_userId) select member);
             if (_result.Count() == 1)
                 Amount.Text = _result.FirstOrDefault().BillAmount_de.ToString();
             else
                 Amount.Text = "0.00";
         }
     }
     else
         Response.Redirect("/Account/InvalidLogin");
 }
Example #18
0
        /*
         Preload the Activity values to the AddSlot Page
         */
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
             Only if it is not PostBack this has to be performed
             */
            if (Session["UserId"] != null)
            {
                if (!IsPostBack)
                {
                    PlanetFitnessDataContext _dataContext = new PlanetFitnessDataContext();

                    /*
                     If We Add a Slot then the Success Message is Displayed based on the Query Paramter that is Parameter in URL
                     */
                    if (Request.QueryString["slotAdded"] != null)
                    {
                        var _bookingStatus = Request.QueryString["slotAdded"].ToString().Trim();
                        if (_bookingStatus == "true")
                        {
                            SuccessMessage.Text = "Slot Added Successful";
                        }
                    }
                    var _activities = (from activity in _dataContext.Activities select activity);
                    Activity.DataSource = _activities;
                    Activity.DataTextField = "Activity_vc";
                    Activity.DataValueField = "ActivityID_in";
                    Activity.DataBind();
                    Activity.Items.Insert(0, new ListItem("--Select--", ""));
                }
            }
            else
                Response.Redirect("/Account/InvalidLogin");
        }