Esempio n. 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (var helper = new DbHelper.Student())
            {
                var user = Page.User as CustomPrincipal;
                if (user != null)
                {
                    if (helper.DoesUserNameExist(user.SchoolId, txtUserName.Text))
                    {
                        valiUserName.ErrorMessage = "Username already exits";
                        valiUserName.IsValid      = false;
                    }
                    if (Page.IsValid)
                    {
                        var createdUser = new Academic.DbEntities.User.Users()
                        {
                            CreatedDate = DateTime.Now
                            ,
                            Email = txtEmail.Text
                            ,
                            FirstName = txtFirstName.Text
                            ,
                            LastName = txtLastName.Text
                            ,
                            IsActive = true
                            ,
                            IsDeleted = false
                            ,
                            UserName = txtUserName.Text
                            ,
                            Password = txtPassword.Text
                            ,
                            Phone = txtPhone1.Text
                            ,
                            MiddleName = txtMiddleName.Text
                        };
                        var student = new Academic.DbEntities.Students.Student()
                        {
                            CRN = txtCRN.Text,
                        };

                        createdUser.SchoolId = user.SchoolId;

                        var saved = helper.AddOrUpdateStudent(createdUser, student, ProgramBatchId);

                        if (saved != null)
                        {
                            //file save
                            SaveFile(user.Id, user.SchoolId, saved);

                            Button btn = (Button)sender;
                            if (btn.ID == "btnSaveNAddMore")
                            {
                                //lblSaveStatus.Visible = true;
                                ResetTextAndCombos();
                                //if (SaveClicked != null)
                                //{

                                //    SaveClicked(this, new MessageEventArgs());
                                //}
                            }
                            else if (btn.ID == "btnCancel")
                            {
                                GoBackToProgramBatch();
                                //if (CloseClicked != null)
                                //{
                                //    CloseClicked(this, DbHelper.StaticValues.CancelClickedMessageEventArgs);
                                //}
                            }
                            else
                            {
                                GoBackToProgramBatch();
                                //if (SaveClicked != null)
                                //{
                                //    SaveClicked(this, new MessageEventArgs() { Message = "close" });
                                //}
                            }
                        }
                        else
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "Couldn't Save.";
                        }
                    }
                }
            }
        }
        protected void SaveStudents()
        {
            using (var helper = new DbHelper.Student())
            {
                var user         = Page.User as CustomPrincipal;
                var usersList    = new List <Academic.DbEntities.User.Users>();
                var studentsList = new List <Academic.DbEntities.Students.Student>();

                var stds = Session["studentsList" + PageKey] as List <Academic.DbEntities.Students.Student>;

                //GridView1.DataSource as List<Academic.DbEntities.Students.Student>;


                if (user != null)
                {
                    if (stds != null)
                    {
                        var unVoided = stds.Where(x => !(x.Void ?? false)).ToList();
                        if (!unVoided.Any())
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "The list doesn't contain any unique students";
                            return;
                        }
                        foreach (var std in unVoided)
                        {
                            var usr = new Academic.DbEntities.User.Users()
                            {
                                CreatedDate = DateTime.Now,
                                FirstName   = std.Name,
                                IsActive    = true,
                                IsDeleted   = false,
                                UserName    = std.CRN,
                                Password    = std.Name,
                                SchoolId    = user.SchoolId
                            };
                            var student = new Academic.DbEntities.Students.Student()
                            {
                                CRN = std.CRN,
                            };
                            usersList.Add(usr);
                            studentsList.Add(student);
                        }
                        var saved = helper.AddOrUpdateStudents(usersList, studentsList, ProgramBatchId);
                        if (saved)
                        {
                            GoBackToProgramBatch();
                        }
                        else
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "Couldn't Save.";
                        }
                    }
                    else
                    {
                        lblSaveError.Visible = true;
                        lblSaveError.Text    = "Couldn't Save. Student data is null. Please try again";
                    }
                }
            }
        }