protected void lnkAdd_Click(object sender, EventArgs e)
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {
            var school = ctx.Schools.Where(s => s.Id == _school).SingleOrDefault();
            var year = school.SchoolYears.Where(y => y.Year.Name == _year).SingleOrDefault();
            StudentGroup group = year.StudentGroups.Where(g => g.Id == _groupId && g.Surveys.Any(sg => sg.Season.Name == _season || string.IsNullOrEmpty(_season))).SingleOrDefault();

            Student student = new Student() { FirstName="", LastName = "", ClassRoom = "", StudentGroup = group};

            ctx.Students.InsertOnSubmit(student);
            ctx.SubmitChanges();
        }
        StudentGrid.EditIndex = 0;
        FillGrid();
    }
Esempio n. 2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        CocaDataContext ctx = new CocaDataContext();
        School sch = new School();
        sch.Name = txtSchool.Text;
        sch.Address1 = txtAddress1.Text;
        sch.Address2 = txtAddress2.Text;
        sch.Address3 = txtAddress3.Text;
        sch.City = txtCity.Text;
        sch.StateId = Convert.ToInt32(ddlStates.SelectedValue);
        sch.Zip = txtZip.Text;

        ctx.Schools.InsertOnSubmit(sch);

        ctx.SubmitChanges();

        MsgText.Text = "School successfully created!.";
        MsgText.Visible = true;
    }
Esempio n. 3
0
    protected void FinishedId_Click(object sender, EventArgs e)
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {
            AnonStudent loggedInStudent = (from AnonStudent a in ctx.AnonStudents where a.Id == this.anonStudentId select a).FirstOrDefault();
            List<SurveyStudent> ssds = (from SurveyStudent ssd in ctx.SurveyStudents
                                                  where ssd.Survey.Equals(loggedInStudent.Survey)
                                                  select ssd).ToList();
            foreach (GridViewRow row in gvStudentSurveyList.Rows)
            {
                long ssdId = (long)gvStudentSurveyList.DataKeys[row.RowIndex].Value;
                SurveyStudent ssd = (from s in ssds where s.Id == ssdId select s).FirstOrDefault();

                TextBox commentText = (TextBox)row.FindControl("txtComment");
                DropDownList bullyAmount = (DropDownList)row.FindControl("ddlBullyTimes");
                DropDownList targetAmount = (DropDownList)row.FindControl("ddlTargetTimes");

                StudentSurveyRating rating = new StudentSurveyRating();

                rating.AnonStudent = loggedInStudent;
                rating.SurveyStudent = ssd;
                int timesBully;
                int timesTarget;
                if(!string.IsNullOrEmpty(bullyAmount.SelectedValue) && int.TryParse(bullyAmount.SelectedValue,out timesBully  ))
                    rating.IsBullyValue = timesBully;
                if(!string.IsNullOrEmpty(targetAmount.SelectedValue) && int.TryParse(targetAmount.SelectedValue, out timesTarget))
                    rating.IsTargetValue = timesTarget;
                rating.Comment = commentText.Text;

                ctx.StudentSurveyRatings.InsertOnSubmit(rating);

            }
            loggedInStudent.SavedDate = DateTime.Today;
            loggedInStudent.LoggedInDate = DateTime.Now;
            Session.Remove(KEY_AnonStudent);
            ctx.SubmitChanges();
            Session.Clear();
            ReturnToLogin();
        }
    }
    protected void StudentGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string firstName = ((TextBox)((GridView)sender).Rows[e.RowIndex].FindControl("fnameEdit")).Text;
        string lastName = ((TextBox)((GridView)sender).Rows[e.RowIndex].FindControl("lnameEdit")).Text;
        string classroom = ((TextBox)((GridView)sender).Rows[e.RowIndex].FindControl("classroomEdit")).Text;
        long id = (long)((GridView)sender).DataKeys[e.RowIndex].Value;

        using (CocaDataContext ctx = new CocaDataContext())
        {
            Student student = (from s in ctx.Students where s.Id == id select s).FirstOrDefault();
            if (student != null)
            {
                student.FirstName = firstName;
                student.LastName = lastName;
                student.ClassRoom = classroom;

                ctx.SubmitChanges();
            }
        }
        StudentGrid.EditIndex = -1;
        FillGrid();
    }
 protected void StudentGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     long id = (long)((GridView)sender).DataKeys[e.RowIndex].Value;
     using (CocaDataContext ctx = new CocaDataContext())
     {
         Student student = (from s in ctx.Students where s.Id == id select s).FirstOrDefault();
         if (student != null)
         {
             ctx.Students.DeleteOnSubmit(student);
             ctx.SubmitChanges();
         }
     }
     StudentGrid.EditIndex = -1;
     FillGrid();
 }