public ActionResult CreateUser(ViewModel userToAdd) { if (!ModelState.IsValid) { TempData["CreateError"] = "Fill all required fields."; userToAdd.Houses = _housesMapper.MapHouses(_housesBusinessLogic.GetHouses()); return(View(userToAdd)); } else { if (userToAdd.SingleUser.House_ID != 0 && userToAdd.SingleUser.FirstName != null && userToAdd.SingleUser.LastName != null && userToAdd.SingleUser.Email != null && userToAdd.SingleUser.Age != null) { Users user = _userMapper.MapUser(_userBusinessLogic.GetUserByUsername(userToAdd.SingleUser.Username)); if (user == null) { _userBusinessLogic.AddUser(_userMapper.MapUser(userToAdd.SingleUser)); user = _userMapper.MapUser(_userBusinessLogic.GetUserByUsername(userToAdd.SingleUser.Username)); if (user.Username == userToAdd.SingleUser.Username) { _houseController.AddPoints(5, userToAdd.SingleUser.House_ID); if (user.House_ID == 1) { TempData["UserCreateSuccess"] = "5 points to GRYFFINDOR!"; } else if (user.House_ID == 2) { TempData["UserCreateSuccess"] = "5 points to SLYTHERIN!"; } else if (user.House_ID == 3) { TempData["UserCreateSuccess"] = "5 points to RAVENCLAW!"; } else if (user.House_ID == 4) { TempData["UserCreateSuccess"] = "5 points to HUFFLEPUFF!"; } return(RedirectToAction("Login", "Users", new { area = "" })); } else { TempData["UsernameError"] = "There was an error creating your account. Please try again."; userToAdd.Houses = _housesMapper.MapHouses(_housesBusinessLogic.GetHouses()); return(View(userToAdd)); } } else { TempData["UsernameError"] = "Username is already in use. Please choose another."; userToAdd.Houses = _housesMapper.MapHouses(_housesBusinessLogic.GetHouses()); return(View(userToAdd)); } } else { TempData["CreateError"] = "All fields are required."; userToAdd.Houses = _housesMapper.MapHouses(_housesBusinessLogic.GetHouses()); return(View(userToAdd)); } } } //create reg user
public HttpResponseMessage AddUser(UserModel userModel) { try { // אם הולידציה נכשלה: if (!ModelState.IsValid) { List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState); return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList)); } if (logic.IsUserExists(userModel)) { List <PropErrors> error = new List <PropErrors>(); error.Add(new PropErrors() { property = "userName or password", errors = new List <string>() { "There is existing user with that userName or password" } }); return(Request.CreateResponse(HttpStatusCode.BadRequest, error)); } UserModel user = logic.AddUser(userModel); return(Request.CreateResponse(HttpStatusCode.Created, user)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public IHttpActionResult AddUser(int id, string password) { var user = new UserDTO() { profileId = id, pass = password }; return(Ok(UsersLogic.AddUser(user))); }
public IActionResult AddUser([FromForm] UserModel userModel) { try { UserModel addedUser = usersLogic.AddUser(userModel); return(Created("https://localhost:44306/api/users/" + addedUser.UserId, addedUser)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public IHttpActionResult AddUser(string userName, string password, string firstName, string lastName, string identityNumber, string email, DateTime birthDate, int roleId) { UsersLogic users = new UsersLogic(); var results = users.AddUser(userName, password, firstName, lastName, identityNumber, email, birthDate, roleId); if (results == 0) { return(NotFound()); } else { return(Ok(results)); } }
public HttpResponseMessage Post(UserRegistration user) { HttpResponseMessage response; JSendMessage json; var userAddress = new UsersAddresses { Address = user.StreetAddress, City = user.City, ZipCode = user.ZipCode, State = user.State }; var userDetails = new Users { UserId = 0, Email = user.Email, Password = user.Password, FirstName = user.FirstName, LastName = user.LastName, Phone = user.Phone, Role = "user", Verified = "no", UsersAddresses = new List <UsersAddresses> { userAddress } }; using (TransactionScope transaction = new TransactionScope()) { var UsersLogic = new UsersLogic(db); var added = UsersLogic.AddUser(userDetails); if (added) { db.SaveChanges(); transaction.Complete(); json = new JSendMessage("success", "Registration was successful! Please, verify your mail address."); response = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("failed", "Registration failed! Please, try another email."); response = Request.CreateResponse(HttpStatusCode.Forbidden, json); } } return(response); }
public IHttpActionResult AddUser(UserDTO user) { return(Ok(UsersLogic.AddUser(user))); }
static void Main(string[] args) { var awardsLogic = new AwardsLogic(); var usersLogic = new UsersLogic(); var b = true; while (b) { Console.WriteLine( "Выберете одно из следующий действий:\n1. Добавить пользователя\n2. Просмотреть всех пользователей\n3." + " Удалить пользователя\n4. Добавить новый тип наград\n5. Просмотреть все награды\n6." + " Просмотреть награды у всех пользователей\n7. Просмотреть пользователей и все их награды\n8. " + "Добавить награду пользователю"); Console.Write("\nВаш выбор: "); var ch = Console.ReadLine(); switch (ch) { case "1": { Console.WriteLine("Введите ФИО, дату рождения и возраст."); Console.Write("ФИО: "); var name = Console.ReadLine(); Console.Write("Дата рождения: "); var date = DateTime.Parse(Console.ReadLine()); Console.Write("Возраст: "); int.TryParse(Console.ReadLine(), out var age); var user = new User(name, date, age); var str = usersLogic.AddUser(user); Console.WriteLine(str); Console.WriteLine(); break; } case "2": { var listUsers = usersLogic.GetUsers(); foreach (var us in listUsers) { Console.WriteLine(us); } Console.WriteLine(); break; } case "3": { Console.WriteLine("Введите ID пользователя, которого нужно удалить"); var listUsers = usersLogic.GetUsers(); foreach (var us in listUsers) { Console.WriteLine(us); } Console.Write("ID: "); int.TryParse(Console.ReadLine(), out var usId); var str = usersLogic.DeleteUser(usId); Console.WriteLine(str); Console.WriteLine(); break; } case "4": { Console.WriteLine("Введите тип награды."); Console.Write("Название: "); var title = Console.ReadLine(); var award = new Award(title); var str = awardsLogic.AddAward(award); Console.WriteLine(str); Console.WriteLine(); break; } case "5": { foreach (var award in awardsLogic.GetAwards()) { Console.WriteLine(award); } Console.WriteLine(); break; } case "6": { var awards = awardsLogic.GetAwards(); foreach (var aw in awards) { Console.WriteLine($"Пользователи у которых имеется {aw.Title}: "); foreach (var us in aw.Users) { Console.WriteLine($" {us.Name}"); } } Console.WriteLine(); break; } case "7": { var users = usersLogic.GetUsers(); foreach (var us in users) { Console.WriteLine($"Награды, имеющиеся у пользователя: {us.Name}"); foreach (var aw in us.Awards) { Console.WriteLine($" {aw.Title}"); } } Console.WriteLine(); break; } case "8": { Console.WriteLine("Введите ID пользователя и ID награды."); Console.Write("ID пользователя: "); int.TryParse(Console.ReadLine(), out var idUs); Console.Write("ID награды: "); int.TryParse(Console.ReadLine(), out var idAw); var str = usersLogic.AddAwardForUser(idUs, idAw); Console.WriteLine(str); Console.WriteLine(); break; } case "9": { b = false; break; } default: { Console.WriteLine("Неверно выбрано действие. Выберите одно из действий в диапазоне от 1 до 8."); break; } } } }