public void UpdateStaff(StaffViewModel objVM) { DBConnectionString.Profile profile = DBConnectionString.Profile.Fetch("select * from profile where userId=@0", objVM.UserId).SingleOrDefault(); DBConnectionString.Staff staff = DBConnectionString.Staff.Fetch("select * from staff where userId=@0", objVM.UserId).SingleOrDefault(); DBConnectionString.User user = DBConnectionString.User.Fetch("select * from Users where userId=@0", objVM.UserId).SingleOrDefault(); if (profile != null) { profile.Title = objVM.Title; profile.DateOfBirth = objVM.DateOfBirth; profile.MobileNumber = objVM.MobileNumber; profile.HomeTelephoneNumber = objVM.HomeTelephoneNumber; profile.EmailAddress1 = objVM.Email; profile.Update(); } if (staff != null) { staff.StaffTypeId = objVM.StaffTypeId; staff.Email = objVM.Email; staff.Update(); } if (user != null) { user.FirstName = objVM.FirstName; user.LastName = objVM.LastName; user.Email = objVM.Email; user.Update(); } objVM.StaffPermission.UserId = objVM.UserId; this.UpdateStaffPermissions(objVM.StaffPermission); }
public bool UpdateProfileImage(Profile objModel) { PetaPoco.Database db = new PetaPoco.Database("DBConnectionString"); DBConnectionString.User user = DBConnectionString.User.SingleOrDefault(objModel.UserId); DBConnectionString.Profile profile = db.Query <DBConnectionString.Profile>("Select * from profile where UserId = @0", objModel.UserId).SingleOrDefault(); try { if (profile != null) { profile.ProfileImageUrl = objModel.ProfileImageUrl; profile.Update(); } else { profile.UserId = objModel.UserId; profile.ProfileImageUrl = objModel.ProfileImageUrl; profile.Insert(); } return(true); } catch (Exception) { throw; } }
public ActionResult RegisterUserStep3(Profile objProfile) { RegistrationToken Token = repository.GetRegistrationCode(objProfile.RegistrationToken); // RegistrationToken objToken = repository.GetRegistrationCode(objProfile.RegistrationToken); StudentContext context = new StudentContext(); Student student = new Student(); Staff staff = new Staff(); if (Token.StaffId != null) { staff = context.Staff.Find(Token.StaffId); } if (Token.StudentId != null) { student = context.Students.Find(Token.StudentId); } //objProfile.RegistrationToken=Toke long userId = WebSecurity.RegisterNewUser(objProfile.UserName, "none", "none", false, objProfile.FirstName, objProfile.LastName, Token.OrganizationId, Token.Token); if (student != null) { student.UserId = userId; } if (staff != null) { staff.UserId = userId; } context.SaveChanges(); DBConnectionString.Profile Profile = new DBConnectionString.Profile(); if (userId != -1) { Profile.UserId = userId; Profile.Title = objProfile.Title; Profile.Address1 = "none"; Profile.Address2 = "none"; Profile.InsertedOn = DateTime.Now; Profile.EmailAddress1 = "*****@*****.**"; Profile.HomeTelephoneNumber = DateTime.Now.Ticks.ToString(); Profile.SecurityQuestionId = 1; Profile.SecurityAnswer = "none"; Profile.DateOfBirth = objProfile.DateOfBirth; Profile.ModifiedOn = null; Profile.MobileNumber = "none"; int recAffected = Convert.ToInt32(Profile.Insert()); string roleName = ((UserRoles)Convert.ToInt16(Token.RoleId)).ToString(); Roles.AddUserToRole(objProfile.UserName, roleName); return(RedirectToAction("RegisterUserStep4", new { userId })); } return(View("RegisterUserStep3", new { token = Token.Token })); }
public bool UpdateUserProfile(Profile objModel) { PetaPoco.Database db = new PetaPoco.Database("DBConnectionString"); DBConnectionString.User user = DBConnectionString.User.SingleOrDefault(objModel.UserId); DBConnectionString.Profile profile = db.Query <DBConnectionString.Profile>("Select * from profile where UserId = @0", objModel.UserId).SingleOrDefault(); try { if (user != null) { user.FirstName = objModel.FirstName; user.LastName = objModel.LastName; user.Update(); } if (profile != null) { profile.Title = objModel.Title; profile.DateOfBirth = objModel.DateOfBirth; profile.MobileNumber = objModel.MobileNumber; profile.HomeTelephoneNumber = objModel.HomeTelephoneNumber; profile.EmailAddress1 = objModel.EmailAddress1; profile.EmailAddress2 = objModel.EmailAddress2; profile.Phone1 = objModel.Phone1; profile.Phone2 = objModel.Phone2; profile.Address1 = objModel.Address1; profile.Address2 = objModel.Address2; profile.ModifiedOn = objModel.ModifiedOn; profile.Update(); } else { profile = new DBConnectionString.Profile(); profile.UserId = objModel.UserId; profile.Title = objModel.Title; profile.DateOfBirth = objModel.DateOfBirth; profile.MobileNumber = objModel.MobileNumber; profile.HomeTelephoneNumber = objModel.HomeTelephoneNumber; profile.EmailAddress1 = objModel.EmailAddress1; profile.EmailAddress2 = objModel.EmailAddress2; profile.Phone1 = objModel.Phone1; profile.Phone2 = objModel.Phone2; profile.Address1 = objModel.Address1; profile.Address2 = objModel.Address2; profile.InsertedOn = DateTime.Now; profile.SecurityAnswer = "None"; profile.Insert(); } return(true); } catch { return(false); } }
public ActionResult RegisterUserStep5(Profile objProfile) { DBConnectionString.User User = DBConnectionString.User.FirstOrDefault("select * from Users where UserId=@0", objProfile.UserId); DBConnectionString.Profile Profile = DBConnectionString.Profile.FirstOrDefault("select * from Profile where UserId=@0", objProfile.UserId); // User.Password = objUser.Password; WebSecurity.ResetPassword(User.Username, objProfile.Password); User = DBConnectionString.User.FirstOrDefault("select * from Users where UserId=@0", objProfile.UserId); Profile.SecurityQuestionId = objProfile.SecurityQuestionId; Profile.SecurityAnswer = objProfile.SecurityAnswer; if (User.Update() > 0 && Profile.Update() > 0) { return(RedirectToAction("RegisterUserStep6", new { userId = User.UserId })); } return(View(objProfile)); }
public ActionResult RegisterUserStep4(Profile objProfile) { DBConnectionString.User User = DBConnectionString.User.FirstOrDefault("select * from Users where UserId=@0", objProfile.UserId); DBConnectionString.Profile Profile = DBConnectionString.Profile.FirstOrDefault("select * from Profile where UserId=@0", objProfile.UserId); User.Email = objProfile.EmailAddress1; Profile.MobileNumber = objProfile.MobileNumber; Profile.HomeTelephoneNumber = objProfile.HomeTelephoneNumber; Profile.EmailAddress1 = objProfile.EmailAddress1; Profile.HomeTelephoneNumber = objProfile.HomeTelephoneNumber; if (User.Update() > 0 && Profile.Update() > 0) { return(RedirectToAction("RegisterUserStep5", new { userId = User.UserId })); } return(View(objProfile)); }
public ActionResult Create(StaffViewModel objViewModel) { string token = this.CreateToken(objViewModel, _userStatistics.UserId, _userStatistics.OrganizationId); if (!(string.IsNullOrEmpty(token))) { long userId = WebSecurity.RegisterNewUser(objViewModel.Email, "none", objViewModel.Email, false, objViewModel.Profile.FirstName, objViewModel.Profile.LastName, objViewModel.OrganizationId, token); DBConnectionString.Profile Profile = new DBConnectionString.Profile(); if (userId != -1) { Profile.UserId = userId; Profile.Title = objViewModel.Profile.Title; Profile.Address1 = "none"; Profile.Address2 = "none"; Profile.InsertedOn = DateTime.Now; Profile.EmailAddress1 = objViewModel.Email; Profile.HomeTelephoneNumber = objViewModel.Profile.HomeTelephoneNumber; Profile.SecurityQuestionId = 1; Profile.SecurityAnswer = "none"; Profile.DateOfBirth = objViewModel.DateOfBirth; Profile.ModifiedOn = null; Profile.MobileNumber = objViewModel.Profile.MobileNumber; int recAffected = Convert.ToInt32(Profile.Insert()); long id = Profile.ProfileId; string roleName = UserRoles.Student.ToString(); //((UserRoles)Convert.ToInt16(Token.RoleId)).ToString(); Roles.AddUserToRole(objViewModel.Email, roleName); //objViewModel.UserId = userId; objViewModel.InsertedBy = _userStatistics.UserId; objViewModel.OrganizationId = _userStatistics.OrganizationId; objViewModel.UserId = userId; objViewModel.StaffId = this.repository.CreateNewStaff(objViewModel); this.repository.AssignSubjectToTeacher(objViewModel); this.repository.SetStaffPermissions(objViewModel);//Assign Staff Permissions SaveFiles(token, this.GetType().Name, objViewModel.StaffId); EmailHandler.Utilities.SendRegistationEmail(token, objViewModel.Email); return(RedirectToAction("Index")); } } StaffViewModel objVM = this.LoadViewModel(); return(View(objVM)); }
public ActionResult Create(StaffViewModel objViewModel) { string token = this.CreateToken(objViewModel, _userStatistics.UserId, _userStatistics.OrganizationId); if (!(string.IsNullOrEmpty(token))) { long userId = WebSecurity.RegisterNewUser(objViewModel.Email, "none", objViewModel.Email, false, objViewModel.Profile.FirstName, objViewModel.Profile.LastName, objViewModel.OrganizationId, token); DBConnectionString.Profile Profile = new DBConnectionString.Profile(); if (userId != -1) { Profile.UserId = userId; Profile.Title = objViewModel.Profile.Title; Profile.Address1 = "none"; Profile.Address2 = "none"; Profile.InsertedOn = DateTime.Now; Profile.EmailAddress1 = objViewModel.Email; Profile.HomeTelephoneNumber = objViewModel.Profile.HomeTelephoneNumber; Profile.SecurityQuestionId = 1; Profile.SecurityAnswer = "none"; Profile.DateOfBirth = objViewModel.DateOfBirth; Profile.ModifiedOn = null; Profile.MobileNumber = objViewModel.Profile.MobileNumber; int recAffected = Convert.ToInt32(Profile.Insert()); long id = Profile.ProfileId; string roleName = UserRoles.Student.ToString(); //((UserRoles)Convert.ToInt16(Token.RoleId)).ToString(); Roles.AddUserToRole(objViewModel.Email, roleName); //objViewModel.UserId = userId; objViewModel.InsertedBy = _userStatistics.UserId; objViewModel.OrganizationId = _userStatistics.OrganizationId; objViewModel.UserId = userId; objViewModel.StaffId = this.repository.CreateNewStaff(objViewModel); this.repository.AssignSubjectToTeacher(objViewModel); this.repository.SetStaffPermissions(objViewModel);//Assign Staff Permissions SaveFiles(token, this.GetType().Name, objViewModel.StaffId); EmailHandler.Utilities.SendRegistationEmail(token, objViewModel.Email); return RedirectToAction("Index"); } } StaffViewModel objVM = this.LoadViewModel(); return View(objVM); }
public bool UpdateStudent(StudentViewModel objViewModel) { PetaPoco.Database db = new PetaPoco.Database("DBConnectionString"); DBConnectionString.User user = DBConnectionString.User.SingleOrDefault(objViewModel.UserId); DBConnectionString.Student student = DBConnectionString.Student.SingleOrDefault(objViewModel.StudentId); DBConnectionString.Profile profile = db.Query <DBConnectionString.Profile>("Select * from profile where UserId = @0", student.UserId).SingleOrDefault(); db.BeginTransaction(); try { if (user != null) { user.FirstName = objViewModel.FirstName; user.LastName = objViewModel.LastName; user.Update(); } if (student != null) { student.ClassId = objViewModel.ClassId; student.CourseId = objViewModel.CourseId; student.DepartmentId = objViewModel.DepartmentId; student.Email = objViewModel.Email; student.FullName = objViewModel.FirstName + " " + objViewModel.LastName; student.ModifiedBy = objViewModel.ModifiedBy; student.ModifiedOn = objViewModel.ModifiedOn; student.SectionId = objViewModel.SectionId; student.Update(); } if (profile != null) { profile.Title = objViewModel.Title; profile.DateOfBirth = objViewModel.DateOfBirth; profile.MobileNumber = objViewModel.MobileNumber; profile.HomeTelephoneNumber = objViewModel.HomeTelephoneNumber; profile.EmailAddress1 = objViewModel.Email; profile.Update(); } //var subjectIdArray = objViewModel.SubjectIds.Split(','); //foreach (var subjectId in subjectIdArray) //{ // DBConnectionString.UserSubject userSubject = db.Query<DBConnectionString.UserSubject>("select * from UserSubjects where UserId = @0 and SubjectId = @1", objViewModel.UserId, subjectId).SingleOrDefault(); // if (userSubject == null) // { // userSubject.UserId = objViewModel.UserId.Value; // userSubject.SubjectId = Convert.ToInt64(subjectId); // userSubject.InsertedOn = DateTime.Now; // userSubject.InsertedBy = objViewModel.InsertedBy; // userSubject.Update(); // } //} db.CompleteTransaction(); return(true); } catch { db.AbortTransaction(); return(false); } }
public ActionResult RegisterUserStep3(Profile objProfile) { RegistrationToken Token = repository.GetRegistrationCode(objProfile.RegistrationToken); // RegistrationToken objToken = repository.GetRegistrationCode(objProfile.RegistrationToken); StudentContext context = new StudentContext(); Student student = new Student(); Staff staff = new Staff(); if (Token.StaffId != null) { staff = context.Staff.Find(Token.StaffId); } if (Token.StudentId != null) { student = context.Students.Find(Token.StudentId); } //objProfile.RegistrationToken=Toke long userId = WebSecurity.RegisterNewUser(objProfile.UserName, "none", "none", false, objProfile.FirstName, objProfile.LastName, Token.OrganizationId, Token.Token); if (student != null) { student.UserId = userId; } if (staff != null) { staff.UserId = userId; } context.SaveChanges(); DBConnectionString.Profile Profile = new DBConnectionString.Profile(); if (userId != -1) { Profile.UserId = userId; Profile.Title = objProfile.Title; Profile.Address1 = "none"; Profile.Address2 = "none"; Profile.InsertedOn = DateTime.Now; Profile.EmailAddress1 = "*****@*****.**"; Profile.HomeTelephoneNumber = DateTime.Now.Ticks.ToString(); Profile.SecurityQuestionId = 1; Profile.SecurityAnswer = "none"; Profile.DateOfBirth = objProfile.DateOfBirth; Profile.ModifiedOn = null; Profile.MobileNumber = "none"; int recAffected = Convert.ToInt32(Profile.Insert()); string roleName = ((UserRoles)Convert.ToInt16(Token.RoleId)).ToString(); Roles.AddUserToRole(objProfile.UserName, roleName); return RedirectToAction("RegisterUserStep4", new { userId }); } return View("RegisterUserStep3", new { token = Token.Token }); }
public bool UpdateUserProfile(Profile objModel) { PetaPoco.Database db = new PetaPoco.Database("DBConnectionString"); DBConnectionString.User user = DBConnectionString.User.SingleOrDefault(objModel.UserId); DBConnectionString.Profile profile = db.Query<DBConnectionString.Profile>("Select * from profile where UserId = @0", objModel.UserId).SingleOrDefault(); try { if (user != null) { user.FirstName = objModel.FirstName; user.LastName = objModel.LastName; user.Update(); } if (profile != null) { profile.Title = objModel.Title; profile.DateOfBirth = objModel.DateOfBirth; profile.MobileNumber = objModel.MobileNumber; profile.HomeTelephoneNumber = objModel.HomeTelephoneNumber; profile.EmailAddress1 = objModel.EmailAddress1; profile.EmailAddress2 = objModel.EmailAddress2; profile.Phone1 = objModel.Phone1; profile.Phone2 = objModel.Phone2; profile.Address1 = objModel.Address1; profile.Address2 = objModel.Address2; profile.ModifiedOn = objModel.ModifiedOn; profile.Update(); } else { profile = new DBConnectionString.Profile(); profile.UserId = objModel.UserId; profile.Title = objModel.Title; profile.DateOfBirth = objModel.DateOfBirth; profile.MobileNumber = objModel.MobileNumber; profile.HomeTelephoneNumber = objModel.HomeTelephoneNumber; profile.EmailAddress1 = objModel.EmailAddress1; profile.EmailAddress2 = objModel.EmailAddress2; profile.Phone1 = objModel.Phone1; profile.Phone2 = objModel.Phone2; profile.Address1 = objModel.Address1; profile.Address2 = objModel.Address2; profile.InsertedOn = DateTime.Now; profile.SecurityAnswer = "None"; profile.Insert(); } return true; } catch { return false; } }