예제 #1
0
        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            var date = DateTime.Now;
            var user = Page.User as CustomPrincipal;



            if (user != null)
            {
                using (var helper = new DbHelper.ActAndRes())
                {
                    var actGrading = new Academic.DbEntities.ActivityAndResource.ActivityGrading()
                    {
                        Id = ActivityGradingId
                        ,
                        ActivityResourceId = ActivityResourceId
                        ,
                        UserClassId = UserClassId
                        ,
                        Remarks = txtRemarks.Text
                    };
                    //grade value obtain
                    //check if textbox is visible or dropdown list is visible
                    var grade = "";
                    try
                    {
                        if (txtGrade.Visible)
                        {
                            //range
                            actGrading.ObtainedGradeMarks = (float)Convert.ToDecimal(txtGrade.Text);
                            var max = (float)Convert.ToDecimal(lblMaximumGrade.Text);
                            var min = (float)Convert.ToDecimal(lblMinimumGradeToPass.Text);
                            if (max.CompareTo(actGrading.ObtainedGradeMarks.Value) <= 0)
                            {
                                lblGradeError.Visible = true;
                            }
                            actGrading.ObtainedGradeId = null;
                            //if (actGrading.ObtainedGradeMarks.Value.CompareTo(min) <= 0)
                            //{
                            //    lblGradeError.Visible = true;
                            //}
                        }
                        else if (ddlGrade.Visible)
                        {
                            //values
                            actGrading.ObtainedGradeMarks = null;
                            actGrading.ObtainedGradeId    = Convert.ToInt32(ddlGrade.SelectedValue);
                        }

                        if (ActivityGradingId > 0)
                        {
                            actGrading.ModifiedDate = date;
                            actGrading.ModifiedById = user.Id;
                        }
                        else
                        {
                            actGrading.GradedById = user.Id;
                            actGrading.GradedDate = date;
                        }
                    }
                    catch
                    {
                        lblGradeError.Visible = true;
                    }
                    var saved = helper.AddOrUpdateActivityGrading(actGrading);
                    if (saved != null)
                    {
                        //Return
                        Response.Redirect("~/Views/ActivityResource/Assignments/AssignmentView.aspx" +
                                          "?SubId=" + SubjectId +
                                          "&arId=" + ActivityId +
                                          "&secId=" + SectionId);
                    }
                    else
                    {
                        lblError.Visible = true;
                    }
                }
            }
        }