protected void btnSave_Click(object sender, EventArgs e) { int count = 0; int ErrorLine = 0; Models.School school = new Models.School(); for (int i = 0; i < gvResult.Rows.Count; i++) { string ID = gvResult.Rows[i].Cells[0].Text; string Name = gvResult.Rows[i].Cells[1].Text; string Lastname = gvResult.Rows[i].Cells[2].Text; string Othername = gvResult.Rows[i].Cells[4].Text; string Address = gvResult.Rows[i].Cells[5].Text; string Origin = gvResult.Rows[i].Cells[3].Text; string LGA = gvResult.Rows[i].Cells[6].Text; string DOB = gvResult.Rows[i].Cells[7].Text; string Sex = gvResult.Rows[i].Cells[8].Text; string GName = gvResult.Rows[i].Cells[9].Text; string GAddress = gvResult.Rows[i].Cells[10].Text; string GPhone = gvResult.Rows[i].Cells[11].Text; string GEmail = gvResult.Rows[i].Cells[12].Text; string Relation = gvResult.Rows[i].Cells[13].Text; var lgaid = DropDownManager.GetLGAIdByName(LGA); var relation = DropDownManager.GetRelationShipByName(Relation); var sex = DropDownManager.GetGenderByName(Sex); if (InsertStudent(Name, Lastname, Othername, DOB, sex, lgaid, Address, GName, GAddress, GPhone, GEmail, relation)) { ++count; } else { ErrorLine = Convert.ToInt32(gvResult.Rows[i].Cells[0].Text); } } DropDownManager.ShowPopUp($"{count} students was successfully added !!"); if (ErrorLine != 0) { DropDownManager.ShowPopUp("Record at Row " + ErrorLine + " was not Inserted#"); } }
protected void btnSave_Click(object sender, EventArgs e) { try { int count = 0; int ErrorLine = 0; Models.School school = new Models.School(); for (int i = 0; i < gvResult.Rows.Count; i++) { //string student_id = gvr.Cells[1].Text; string id = gvResult.Rows[i].Cells[0].Text; string name = gvResult.Rows[i].Cells[1].Text; string Address = gvResult.Rows[i].Cells[2].Text; string Email = gvResult.Rows[i].Cells[4].Text; string MobileNo = gvResult.Rows[i].Cells[5].Text; string LGA = gvResult.Rows[i].Cells[3].Text; string Type = gvResult.Rows[i].Cells[6].Text; string category = gvResult.Rows[i].Cells[7].Text; string DateOfInCorporation = gvResult.Rows[i].Cells[8].Text; string PrincipalName = gvResult.Rows[i].Cells[9].Text; if (Type == "Public") { Type = "1"; } else { Type = "2"; } if (category == "Primary") { category = "1"; } else { category = "2"; } var lgaid = DropDownManager.GetLGAIdByName(LGA); //Create User var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>(); var user = new ApplicationUser() { UserName = Email, Email = Email, PhoneNumber = MobileNo }; IdentityResult result = manager.Create(user, "@Ab1234567"); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 //string code = manager.GenerateEmailConfirmationToken(user.Id); //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request); manager.AddToRole(user.Id, "School"); school.Name = name; school.Address = Address; school.Email = Email; school.MobileNo = Convert.ToDecimal(MobileNo); school.SchoolTypeId = int.Parse(Type); school.NameOfPrincipal = PrincipalName; school.LocalGovernmentID = lgaid; school.DateOfIncorporation = Convert.ToDateTime(DateOfInCorporation); school.DateCreated = DateTime.Now; school.CategoryId = int.Parse(category); school.CreatedBy = User.Identity.GetUserId(); school.UserId = user.Id; unitOfWork.School.Insert(school); unitOfWork.Save(); count++; } else { ErrorLine = Convert.ToInt32(gvResult.Rows[i].Cells[0].Text); } } DropDownManager.ShowPopUp(count.ToString() + " Records Successfully Inserted !!!"); if (ErrorLine != 0) { DropDownManager.ShowPopUp("Record at Row " + ErrorLine + " was not Inserted#"); } } catch (Exception ex) { // lblError.Text = ErrorLog.InsertErrorLog(ex.Message) + " Please Contact Admin"; } }