protected User CreateUser() { User user = new User(); Role role = new Role(); try { //User user.Name = textboxName.Value; user.LastName = textboxLastName.Value; user.Username = textboxUsernameR.Value; user.Password = textboxPasswordR.Value; if (hiddenConditionValue.Value.Equals(string.Empty)) { role.Id = Convert.ToInt32(selectCondition.Items[0].Value); role.Name = selectCondition.Items[0].Text; } else { role.Id = Convert.ToInt32(hiddenConditionValue.Value); role.Name = selectCondition.Items.FindByValue(hiddenConditionValue.Value).Text; } user.Role = role; user.UniversityCard = Convert.ToInt32(textboxUniversityCard.Value); return user; } catch (FormatException) { buttonStyle.buttonStyleRed(buttonErrors, "Invalid data, please check it or contact with us."); return null; } }
public int UpdateRules(User user) { try { if (user.Name.Equals(string.Empty)) return 1; else if (user.LastName.Equals(string.Empty)) return 2; else if (user.Username.Equals(string.Empty)) return 3; else if (user.Password.Equals(string.Empty)) return 4; else if (user.UniversityCard.Equals(string.Empty)) return 6; else { userData.UpdateUser(user); return 0; } } catch (SqlException) { return 5; } }
public int RegistrationRules(User user, Campus campus) { try { if (user.Name.Equals(string.Empty)) return 1; else if (user.LastName.Equals(string.Empty)) return 2; else if (user.Username.Equals(string.Empty)) return 3; else if (user.Password.Equals(string.Empty)) return 4; else if (user.UniversityCard.Equals(string.Empty)) return 6; else if (campus.Id.Equals(string.Empty)) return 7; else if (campus.Name.Equals(string.Empty)) return 8; else { userData.InsertUser(user, campus); return 0; } } catch (SqlException) { return 5; } }
public User sendUser(DataTable dataTableUserInfo) { User user = new User(); Role role = new Role(); user.Name = dataTableUserInfo.Rows[0]["Name"].ToString(); user.LastName = dataTableUserInfo.Rows[0]["LastName"].ToString(); user.Username = dataTableUserInfo.Rows[0]["UserName"].ToString(); user.Password = dataTableUserInfo.Rows[0]["Password"].ToString(); role.Id = Convert.ToInt32(dataTableUserInfo.Rows[0]["RoleId"]); user.Role = role; user.UniversityCard = Convert.ToInt32(dataTableUserInfo.Rows[0]["UniversityCard"]); return user; }
public void UpdateUser(User user) { SqlConnection connection = ManageDatabaseConnection("Open"); using (SqlCommand update = new SqlCommand(@"UpdateUser", connection)) { update.CommandType = CommandType.StoredProcedure; update.Parameters.Add("@Name", SqlDbType.VarChar).Value = user.Name; update.Parameters.Add("@LastName", SqlDbType.VarChar).Value = user.LastName; update.Parameters.Add("@UserName", SqlDbType.VarChar).Value = user.Username; update.Parameters.Add("@Password", SqlDbType.VarChar).Value = EncryptPassword(user.Password); update.Parameters.Add("@RoleId", SqlDbType.Int).Value = user.Role.Id; update.Parameters.Add("@UniversityCard", SqlDbType.Int).Value = user.UniversityCard; update.ExecuteNonQuery(); } connection = ManageDatabaseConnection("Close"); }
public void InsertUser(User user, Campus campus) { SqlConnection connection = ManageDatabaseConnection("Open"); using (SqlCommand insert = new SqlCommand(@"InsertUser", connection)) { insert.CommandType = CommandType.StoredProcedure; insert.Parameters.Add("@Name", SqlDbType.VarChar).Value = user.Name; insert.Parameters.Add("@LastName", SqlDbType.VarChar).Value = user.LastName; insert.Parameters.Add("@UserName", SqlDbType.VarChar).Value = user.Username; insert.Parameters.Add("@Password", SqlDbType.VarChar).Value = EncryptPassword(user.Password); insert.Parameters.Add("@RoleId", SqlDbType.Int).Value = user.Role.Id; insert.Parameters.Add("@RoleName", SqlDbType.VarChar).Value = user.Role.Name; insert.Parameters.Add("@UniversityCard", SqlDbType.Int).Value = user.UniversityCard; insert.Parameters.Add("@CampusId", SqlDbType.Int).Value = campus.Id; insert.Parameters.Add("@CampusName", SqlDbType.VarChar).Value = campus.Name; insert.ExecuteNonQuery(); } connection = ManageDatabaseConnection("Close"); }
protected User CreateUser() { User user = new User(); Role role = new Role(); try { //Creating user user.Name = textboxName.Value; user.LastName = textboxLastName.Value; user.Username = textboxUsername.Value; user.Password = textboxPasswordShowed.Value; role.Id = Convert.ToInt32(Session["User-ConditionId"]); user.Role = role; user.UniversityCard = Convert.ToInt32(textboxUniversityCard.Value); return user; } catch { buttonStyle.buttonStyleRed(buttonErrors, "An error ocurred validating your new data, please check it."); return null; } }
protected void UpdateUser(User user) { if (user != null) { UserBussinessRules userBussinessRules = new UserBussinessRules(); //For password validation string newPassword = textboxPasswordShowed.Value; string passwordHashed = Session["User-PasswordHashed"].ToString(); bool verify = BCrypt.Net.BCrypt.Verify(newPassword, passwordHashed); //Updating user switch (userBussinessRules.UpdateRules(user)) { case 0: if (verify == false) { Response.Redirect("Default.aspx"); } else { Session["User-Name"] = textboxName.Value; Session["User-LastName"] = textboxLastName.Value; FillTableWithUserInfo(); DisablingControls(); } buttonStyle.buttonStyleBlue(buttonErrors, "User updated succesful."); break; case 1: buttonStyle.buttonStyleWhite(buttonErrors, "The name field is empty."); break; case 2: buttonStyle.buttonStyleRed(buttonErrors, "The lastname field is empty."); break; case 3: buttonStyle.buttonStyleWhite(buttonErrors, "The username field is empty."); break; case 4: buttonStyle.buttonStyleRed(buttonErrors, "The password field is empty."); break; case 5: buttonStyle.buttonStyleWhite(buttonErrors, "An error ocurred during your update."); break; case 6: buttonStyle.buttonStyleRed(buttonErrors, "The university card field is empty."); break; } } }
protected void InsertUser(User user, Campus campus) { if (user != null) { if (campus != null) { UserBussinessRules userBussinessRules = new UserBussinessRules(); switch (userBussinessRules.RegistrationRules(user, campus)) { case 0: textboxName.Value = string.Empty; textboxLastName.Value = string.Empty; textboxUsernameR.Value = string.Empty; textboxPasswordR.Value = string.Empty; textboxUniversityCard.Value = string.Empty; buttonStyle.buttonStyleBlue(buttonErrors, "User registered sucessful."); break; case 1: buttonStyle.buttonStyleWhite(buttonErrors, "The name field is empty."); break; case 2: buttonStyle.buttonStyleRed(buttonErrors, "The lastname field is empty."); break; case 3: buttonStyle.buttonStyleWhite(buttonErrors, "The username field is empty."); break; case 4: buttonStyle.buttonStyleRed(buttonErrors, "The password field is empty."); break; case 5: buttonStyle.buttonStyleWhite(buttonErrors, "An error ocurred during your registration."); break; case 6: buttonStyle.buttonStyleRed(buttonErrors, "The university card field is empty."); break; case 7: buttonStyle.buttonStyleWhite(buttonErrors, "The campus id field is empty."); break; case 8: buttonStyle.buttonStyleRed(buttonErrors, "The campus name field is empty."); break; } } } }
protected Reservation CreateReservation() { Reservation reservation = new Reservation(); Space space = new Space(); User user = new User(); Vehicle vehicle = new Vehicle(); DateTime checkIn = DateTime.Now; DateTime checkOut = DateTime.Now; TimeSpan initialHour = new TimeSpan(); TimeSpan finalHour = new TimeSpan(); try { if (hiddenCampusValue.Value.Equals(string.Empty)) space.ParkingCampusId = Convert.ToInt32(selectCampus.Items[0].Value); else space.ParkingCampusId = Convert.ToInt32(hiddenCampusValue.Value); } catch (FormatException) { buttonStyle.buttonStyleRed(buttonErrors, "The campus select is empty."); return null; } try { if (hiddenParkingValue.Value.Equals(string.Empty)) space.ParkingId = Convert.ToInt32(selectParking.Items[0].Value); else space.ParkingId = Convert.ToInt32(hiddenParkingValue.Value); } catch (FormatException) { buttonStyle.buttonStyleRed(buttonErrors, "The parking select is empty."); return null; } try { space.Id = Convert.ToInt32(hiddenSpaceValue.Value); } catch (FormatException) { buttonStyle.buttonStyleRed(buttonErrors, "Please, select a space."); return null; } try { if (hiddenVehicleValue.Value.Equals(string.Empty)) vehicle.VehiclePlate = selectVehicle.Items[0].Value; else vehicle.VehiclePlate = hiddenVehicleValue.Value; } catch (FormatException) { buttonStyle.buttonStyleRed(buttonErrors, "The vehicle select is empty."); return null; } user.Username = Session["User-UserName"].ToString(); reservation.Space = space; reservation.User = user; reservation.Vehicle = vehicle; initialHour = CreateCheckIn(initialHour); finalHour = CreateCheckOut(finalHour); checkIn = checkIn.Date + initialHour; checkOut = checkOut.Date + finalHour; reservation.CheckIn = checkIn; reservation.CheckOut = checkOut; return reservation; }