private void btnAddEditUser_Click(object sender, RoutedEventArgs e) { UserDAO userDAO = new UserDAO(); if (mode == Mode.ADD) { User user = new User() { Name = tbName.Text.Trim(), Surname = tbSurname.Text.Trim(), Username = tbUsername.Text.Trim(), Password = tbPassword.Text.Trim(), UserType = (TypeOfUser)cbUserType.SelectedItem }; MainWindow.usersList.Add(user); userDAO.Add(user); } else { user.Name = tbName.Text.Trim(); user.Surname = tbSurname.Text.Trim(); user.Password = tbPassword.Text.Trim(); user.UserType = (TypeOfUser)cbUserType.SelectedItem; userDAO.Update(user); } Close(); }
public void GivenThereIsAUserCalledVintem(string username) { _currentUser = new User(username); var userRepository = new UserDAO(); userRepository.Add(_currentUser); userRepository.Commit(); }
public UserModel AddUser(string userId, string firstname, string lastname) { try { if ( userId == null || userId.Length == 0 || firstname == null || firstname.Length == 0 || lastname == null || lastname.Length == 0 ) { throw new Exception("Missing parameter to add new user."); } var newUser = UserDAO.Add(new User() { UserId = userId, Firstname = firstname, Lastname = lastname }); if (newUser == null) { throw new Exception("User already registered."); } return(new UserModel() { UserId = newUser.UserId, Firstname = newUser.Firstname, Lastname = newUser.Lastname }); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.InternalServerError); } }
public void AddUser(User user) { if (user != null) { userDAO.Add(user); } else { throw new APIException(StatusCodes.Status422UnprocessableEntity); } }
public override bool Add(object dto) { bool isCan = false; try { isCan = dao.Add(dto); } catch (Exception ex) { Log((dto as UserDTO).Page, "Error", ex.ToString()); } return(isCan); }
static void Main9() { var murilo = new PhysicalPerson { Name = "Murilo", CPF = 11233433.ToString() }; var caelum = new LegalPerson { Name = "Murilo", CNPJ = 11233433.ToString() }; var _session = NHibernateHelper.OpenSession(); var userDAO = new UserDAO(_session); userDAO.Add(murilo); userDAO.Add(caelum); _session.Close(); Console.Read(); }
public static bool Register(User User) { try { User.Role = RoleDAO.getRoleById(COM.CONST.ROLE.NORMALUSER); User.CreatedDate = DateTime.Now; return(UserDAO.Add(User)); } catch (Exception ex) { Logger.getInstance().log(ex.ToString()); return(false); } }
static void Main1() { var _session = NHibernateHelper.OpenSession(); var daoUser = new UserDAO(_session); var user = new PhysicalPerson { Name = "Murilo" }; daoUser.Add(user); _session.Close(); Console.Read(); }
public ActionResult Add([FromBody] User user) { try { User existingUser = null; using (var userDAO = new UserDAO()) { existingUser = userDAO.GetByEmail(user.Email); if (existingUser != null) { user.Id = existingUser.Id; } else { user.Id = userDAO.Add(user); } } if (user.Id != 0) { Token token = new Token(user); var emurbMail = new SystemMail(_smtp, _port, _login, _password); if (emurbMail.SendNewPasswordMail(Request, token)) { using (var tokenDAO = new TokenDAO()) tokenDAO.Add(token); return(StatusCode(201, new { Message = (existingUser != null) ? "Usuário já cadastrado, email reenviado com sucesso" : "Adicionado com sucesso" })); } return(StatusCode(424, new { Message = "Falha ao enviar email" })); } return(StatusCode(304, new { Message = "Não adicionado" })); } catch (Exception ex) { return(StatusCode(500, new { Message = "Falha" })); } }
public ActionResult Validate(User user) { try { if (ModelState.IsValid) { if (user.Password.Length > 4) { if (user.BirthDate <= DateTime.Now && user.BirthDate.Year >= 1900) { UserDAO dao = new UserDAO(); if (!dao.IsUnique(user)) { user.CrtDate = DateTime.Now; user.Picture = "../../../media/default/default-user.png"; dao.Add(user); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("user.NotUniq", "Username Already been used"); } else { ModelState.AddModelError("user.BirthNA", "Your birth Date is not acceptable"); } } else { ModelState.AddModelError("user.Password4", "Your password needs to be at least 5 characters"); } } CountryDAO cdao = new CountryDAO(); LanguageDAO ldao = new LanguageDAO(); ViewBag.User = user; ViewBag.Class = "alert alert-danger"; ViewBag.Country = cdao.List(); ViewBag.Lang = ldao.List(); return(View("Register")); } catch { return(RedirectToAction("Index", "Home")); } }
public ActionResult SignUp(FormCollection collection) { try { User user = new User(); user.UserName = collection["UserName"]; user.Password = collection["Password"]; if (UserDAO.CountByUserName(user.UserName) > 0) { return(View()); } UserDAO.Add(user); return(RedirectToAction("Index")); } catch { return(View()); } }
public void GivenNewUserShouldAddInDb() { var data = new List <User>().AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.User).Returns(mockSet.Object); var dao = new UserDAO(mockContext.Object); dao.Add(new User() { Id = 0, UserId = "XXXX" }); mockSet.Verify(m => m.Add(It.IsAny <User>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
private void PopulateComboBoxes() { try { List <User> users = new UserDAO().GetUsers(function: User.Function.USER.ToString()); users.Add(new User() { Id = -1, Username = "******" }); FineUserBox.ItemsSource = users; UserBox.ItemsSource = users; LicenseCategoryComboBox.ItemsSource = Enum.GetValues(typeof(Vehicle.LicenseCategories)); VehicleBox.ItemsSource = new VehicleDAO().GetVehicles(); } catch (Exception ex) { NotificationLabel.ShowError("Something went wrong with retrieving data"); DebugLog.WriteLine(ex); } }
public void GivenExistingUserForCreationShouldReturnNull() { var data = new List <User> { new User() { Id = 0, UserId = "XXXX" } }.AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.User).Returns(mockSet.Object); var dao = new UserDAO(mockContext.Object); var result = dao.Add(new User() { UserId = "XXXX" }); Assert.AreEqual(null, result); }
public ActionResult Add(User user) { if (ModelState.IsValid) { //var dao = new UserDAO(); var encryptedMd5Pas = Encryptor.MD5Hash(user.Password); user.CreatedDate = DateTime.Now; user.CreatedBy = this.UserName; user.Password = encryptedMd5Pas; long id = dao.Add(user); if (id > 0) { SetAlert("Thêm user thành công", "success"); return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Thêm user không thành công"); } } return(View("Index")); }
public void Add(User t) { UserDAO.Add(t); }
public ActionResult AddUser(User user) { userDAO.Add(user); return(RedirectToAction("Index")); }
public void CreateUser(User user) { userRepo.Add(user); }
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!(e.OriginalSource is TabControl)) { return; } NotificationLabel.Content = ""; if (AllRentalsTab.IsSelected) { List <Rent> allRentals = new RentDAO().GetRents(); if (allRentals.Count == 0) { NotificationLabel.ShowError("There aren't any rentals"); } AllRentalsTable.ItemsSource = allRentals; } else if (AllFinesTab.IsSelected) { List <Damage> allDamages = new DamageDAO().GetDamages(); if (allDamages.Count == 0) { NotificationLabel.ShowSuccess("There are no fines"); } try { List <User> users = new UserDAO().GetUsers(function: User.Function.USER.ToString()); FineUserBox.ItemsSource = users; LicenseCategoryComboBox.ItemsSource = Enum.GetValues(typeof(Vehicle.LicenseCategories)); } catch (Exception ex) { NotificationLabel.ShowError("Something went wrong with retrieving data"); DebugLog.WriteLine(ex); } AllDamagesTable.ItemsSource = allDamages; } else if (AllCarsTab.IsSelected) { List <Vehicle> myVehicles = new VehicleDAO().GetVehicles(); if (myVehicles != null & myVehicles.Count() == 0) { NotificationLabel.ShowError("No vehicles to display"); } try { List <User> users = new UserDAO().GetUsers(function: User.Function.USER.ToString()); users.Add(new User() { Id = -1, Username = "******" }); UserBox.ItemsSource = users; LicenseCategoryComboBox.ItemsSource = Enum.GetValues(typeof(Vehicle.LicenseCategories)); } catch (Exception ex) { NotificationLabel.ShowError("Something went wrong with retrieving data"); DebugLog.WriteLine(ex); } VehicleTable.ItemsSource = myVehicles; } else if (SettingsTab.IsSelected) { User currentUser = UserManager.CurrentUser; try { UserDetails details = new UserDetailsDAO().GetUserDetails(userId: currentUser.Id).First(); UsernameBox.Text = currentUser.Username; NameBox.Text = currentUser.Name; SurnameBox.Text = currentUser.Surname; EmailBox.Text = details.Email; StreetBox.Text = details.Street; CityBox.Text = details.City; ZipCodeBox.Text = details.ZipCode; CountryBox.Text = details.Country; BirthDatePicker.SelectedDate = details.BirthDate; } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured! Could not retrieve your data!"); return; } } else if (AllUsersTab.IsSelected) { try { AllUsersTable.ItemsSource = new UserDAO().GetUsers(); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not retrieve all users"); } } }