示例#1
0
        private static void CreateUser()
        {
            System.Console.WriteLine("\tEnter name. \t***leave blank line if you want default name***");
            string name = System.Console.ReadLine();

            if (string.IsNullOrEmpty(name))
            {
                name = "DefaultUserName";
            }

            System.Console.WriteLine("\tEnter date of birth. Example : 20.12.2000 - Day.Month.Year");
            string date = System.Console.ReadLine();

            while (!DateValid(date))
            {
                System.Console.WriteLine("Invalid date of birth. Try again.");
                date = System.Console.ReadLine();
            }

            DateTime validDate = DateTime.Parse(date);
            User     user      = new User();

            user.Name        = name;
            user.DateOfBirth = validDate;
            userLogic.Add(user);
            System.Console.WriteLine("\tUser successfully added.");
        }
示例#2
0
 public void InitTest()
 {
     _user = new UserDto()
     {
         Username = "******",
         Email    = "*****@*****.**",
         Password = "******"
     };
     _userLogic.Add(_user);
     _userList = new List <UserDto>(_userLogic.GetAllUsers());
     _user.Id  = _userList.Last().Id;
 }
示例#3
0
        private static void AddUser(IUserLogic logic)
        {
            Console.Clear();
            Console.WriteLine("Enter user name: ");
            var name = Console.ReadLine();

            Console.WriteLine("Enter user date of birth: ");
            var dateOfBirth = Console.ReadLine();

            if (DateTime.TryParse(dateOfBirth, out DateTime date))
            {
                var user = new User()
                {
                    Name        = name,
                    DateOfBirth = date,
                };
                if (logic.Add(user))
                {
                    Console.Clear();
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Error: user's data is incorrect");
                }
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Error: user's birth date is incorrect (required dd/MM/yyyy)");
            }
        }
示例#4
0
        private static void CreateUser()
        {
            string name = string.Empty;

            while (name == string.Empty)
            {
                Console.Write("Input user name: ");
                name = Console.ReadLine();
            }

            DateTime dateOfBirth = DateTime.Now;
            bool     success     = false;

            while (!success)
            {
                Console.Write("Input user date of birth: ");

                success = DateTime.TryParse(Console.ReadLine(), out dateOfBirth) &&
                          dateOfBirth.Year <= DateTime.Now.Year &&
                          DateTime.Now.Year - dateOfBirth.Year <= 150;
            }

            var user = new User
            {
                Name        = name,
                DateOfBirth = dateOfBirth,
            };

            userLogic.Add(user);
            Console.WriteLine($"Added: {user}");
            Pause();
        }
示例#5
0
        private static void AddUser()
        {
            string   name;
            DateTime dateOfBirth;

            Console.WriteLine("Введите имя:");
            name = Console.ReadLine();
            while (name.Length > 50)
            {
                Console.WriteLine("Ошибка, слишком длинное имя! Максимум 50 символов" + Environment.NewLine +
                                  "Введите заново: ");
                name = Console.ReadLine();
            }
            Console.WriteLine("Введите дату (гггг/мм/дд):");
            while (!DateTime.TryParse(Console.ReadLine(), out dateOfBirth))
            {
                Console.WriteLine("Ошибка, введен неверный формат!" + Environment.NewLine +
                                  "Введите заново: ");
            }

            try
            {
                _userLogic.Add(new User()
                {
                    Name        = name,
                    DateOfBirth = dateOfBirth
                });
            }
            catch (SqlTypeException)
            {
                Console.WriteLine("Неверная дата рождения");
            }
        }
示例#6
0
 public static void AddUser()
 {
     try
     {
         Console.WriteLine("Введите: Имя");
         string name = Console.ReadLine();
         Console.WriteLine("Введите: Дату рождения(дд/мм/гггг или дд.мм.гггг)");
         string[] date = Console.ReadLine().Split('/', '.');
         DateTime dat  = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]));
         if (dat > DateTime.Now)
         {
             throw new ArgumentOutOfRangeException();
         }
         userLogic.Add(name, dat);
         Console.WriteLine("Пользователь добавлен.");
     }
     catch (ArgumentOutOfRangeException e)
     {
         Console.WriteLine("Неправильно указана дата");
     }
     catch (System.Data.SqlClient.SqlException e)
     {
         Console.WriteLine("Пользователь с таким именем уже существует");
     }
 }
        public ActionResult Registration(RegistrationMV model)
        {
            if (ModelState.IsValid)
            {
                RegistrationMV user   = null;
                var            config = new MapperConfiguration(cfg => cfg.CreateMap <User, RegistrationMV>());
                var            mapper = new Mapper(config);

                user = mapper.Map <RegistrationMV>(userLogic.FindUserByLogin(model.Login));
                if (user == null)
                {
                    userLogic.Add(model.Login, model.Password, model.Surname, model.Name, model.Patronymic, model.Age);
                    user = mapper.Map <RegistrationMV>(userLogic.FindUserById(model.Id));
                }
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Login, true);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Пользователь с таким логином уже существует");
            }

            return(RedirectToAction("Index", "Home"));
        }
示例#8
0
 public IActionResult Post([FromBody] UserModelIn userIn)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var user         = mapper.Map <UserModelIn, UserEntity>(userIn);
             var id           = userLogic.Add(user);
             var addedUser    = userLogic.GetById(id);
             var addedUserOut = mapper.Map <UserEntity, UserModelOut>(addedUser);
             return(Created("Posted succesfully", addedUserOut));
         }
         catch (ArgumentException ex)
         {
             return(BadRequest(ex.Message));
         }
         catch (Exception ex)
         {
             return(BadRequest(ex.Message));
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
示例#9
0
 public ActionResult Register(RegistrationViewModel model)
 {
     try
     {
         var newUser = mapper.Map <RegistrationViewModel, User>(model);
         if (ModelState.IsValid)
         {
             if (user.Add(newUser))
             {
                 return(RedirectToAction("Login"));
             }
             else
             {
                 ModelState.AddModelError("", "A user with this Username already exists");
             }
         }
         else
         {
             ModelState.AddModelError("", "Invalid Username or Password");
         }
         return(View(model));
     }
     catch
     {
         return(View(model));
     }
 }
示例#10
0
        private static void AddUser(IUserLogic userLogic)
        {
            string input;

            Console.WriteLine("input user Name");
            input = Console.ReadLine();

            var user = new User();

            user.Name = input;

            Console.WriteLine("input user date of birth in format dd.mm.yyyy");
            input = Console.ReadLine();

            if (!DateTime.TryParse(input, out var datebirth) || datebirth > DateTime.Now)
            {
                Console.WriteLine("Date of birth is not correct");
            }
            else
            {
                user.DateOfBirth = datebirth;

                userLogic.Add(user);

                Console.WriteLine("User added");
                ShowMenu();
            }
        }
        private UserResponse AddOrUpdateUser(Boolean update, UserRequest userRequest)
        {
            UserResponse userResponse = new UserResponse();

            userResponse.ResultMessages = new List <String>();
            if (userRequest != null && userRequest.Users != null && userRequest.Users.Count > 0)
            {
                Boolean succeededOne = false;

                try
                {
                    userResponse.Users = new List <User>();
                    using (ILifetimeScope scope = NippsIoCHelper.IoCContainer.BeginLifetimeScope())
                    {
                        IUserLogic userLogic = scope.Resolve <IUserLogic>();
                        foreach (User user in userRequest.Users)
                        {
                            try
                            {
                                if (update)
                                {
                                    userLogic.Update(user);
                                }
                                else
                                {
                                    userLogic.Add(user);
                                }
                                succeededOne = true;
                            }
                            catch (Exception ex)
                            {
                                if (succeededOne)
                                {
                                    userResponse.Result = Result.SUCCESSWITHWARN;
                                }
                                else
                                {
                                    userResponse.Result = Result.FAIL;
                                }

                                userResponse.ResultMessages.Add(ex.ToString());
                                mLogger.Error("{0}\n{1}", user, ex);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    userResponse.Result = Result.FAIL;
                    userResponse.ResultMessages.Add(ex.ToString());
                    mLogger.Error("{0}", ex);
                }
            }
            else
            {
                userResponse.Result = Result.FAIL;
                userResponse.ResultMessages.Add(ResultMessagesHelper.ToString(ResultMessages.REQUEST_INVALID_PARAMETER));
            }
            return(userResponse);
        }
示例#12
0
        public static void Authorization()
        {
            Console.Clear();
            Console.WriteLine("Выберите действие: \n 1.Войти \n 2.Регистрация");
            switch (Console.ReadLine())
            {
            case "1":
                Console.WriteLine("Введите логин:");
                string Login = Console.ReadLine();
                Console.WriteLine("Введите пароль:");
                string Password = Console.ReadLine();
                userLogic.Authorization(Login, Password);
                ID            = userLogic.FindForLogin(Login);
                authorization = true;
                Check();
                break;

            case "2":
                Console.WriteLine("Введите имя:");
                string Name = Console.ReadLine();
                Console.WriteLine("Введите дату рождения:");
                DateTime DateOfBrith = new DateTime(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()));
                Console.WriteLine("Введите логин:");
                string login = Console.ReadLine();
                checkLogin(ref login);
                Console.WriteLine("Введите пароль:");
                string password = Console.ReadLine();

                userLogic.Add(new User(Name, DateOfBrith, login, password));

                authorization = true;
                break;
            }
        }
示例#13
0
        private static void CreateUser()
        {
            string name;

            while (true)
            {
                Console.WriteLine("Input name:");
                name = Console.ReadLine();
                try
                {
                    if (Regex.IsMatch(name, Constants.USERNAME_REGEX))
                    {
                        break;
                    }
                    else
                    {
                        throw new InvalidInputException("Invalid name");
                    }
                }
                catch (InvalidInputException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            DateTime dateOfBirth;

            while (true)
            {
                Console.WriteLine("Input date of birth:");
                try
                {
                    if (DateTime.TryParse(Console.ReadLine(), out dateOfBirth) &&
                        dateOfBirth.Year <= DateTime.Now.Year &&
                        DateTime.Now.Year - dateOfBirth.Year <= Constants.MAX_AGE)
                    {
                        break;
                    }
                    else
                    {
                        throw new InvalidInputException("Invalid date of birth");
                    }
                }
                catch (InvalidInputException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            var user = new User
            {
                Name        = name,
                DateOfBirth = dateOfBirth,
            };

            userLogic.Add(user);
            Console.WriteLine($"Added: {user}");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
示例#14
0
        public void AddNewUserTest()
        {
            userRepository.SetupSequence(r => r.Exists(It.IsAny <Expression <Func <UserEntity, bool> > >()))
            .Returns(false).Returns(false).Returns(true).Returns(true);
            userRepository.Setup(u => u.Add(It.IsAny <UserEntity>())).Verifiable();
            userRepository.Setup(r => r.FirstOrDefault(It.IsAny <Expression <Func <UserEntity, bool> > >())).Returns(testUserEntity);
            unitOfWork.Setup(r => r.Save());
            userRepository.Setup(r => r.FirstOrDefault(It.IsAny <Expression <Func <UserEntity, bool> > >())).Returns(testUserEntity);

            var        result     = userLogic.Add(testUserEntity);
            UserEntity userResult = unitOfWork.Object.UserRepository.FirstOrDefault(u => u.Id == result);

            userRepository.VerifyAll();
            Assert.IsNotNull(result);
            Assert.AreEqual(testUserEntity.Id, userResult.Id);
            Assert.AreEqual(testUserEntity.CompleteName, userResult.CompleteName);
        }
示例#15
0
        private void AddUser()
        {
            User user = GetUserFromConsole();

            _userLogic.Add(user);

            Console.WriteLine("{0}The user successfully added:{0}  {1}{0}", Environment.NewLine, user.ToString());
        }
示例#16
0
文件: PL.cs 项目: ZaXoD123/XT-2018Q4
        public static void Add(string name, DateTime date)
        {
            var user = new User();

            user.DateOfBirth = date;
            user.Name        = name;
            userLogic.Add(user);
            userLogic.Exit();
        }
示例#17
0
        private static void AddUser(IUserLogic userLogic)
        {
            var user = new User
            {
                Name        = "David",
                DateOfBirth = DateTime.Now
            };

            userLogic.Add(user);
        }
示例#18
0
        public static void AddUser(string name, string lastName, DateTime dateOfBirth)
        {
            var user = new User
            {
                FirstName   = name,
                LastName    = lastName,
                DateOfBirth = dateOfBirth
            };

            userLogic.Add(user);
        }
示例#19
0
        public void logic_should_add_a_user()
        {
            var user = new User {
                Name = "test"
            };

            _repo.Setup(q => q.Add(user)).Returns(user);

            var actual = _logic.Add(user);

            Assert.AreEqual(user, actual);
        }
示例#20
0
        private void AddUser()
        {
            Console.WriteLine("Enter Name");
            Console.Write(">");
            var name = GetUserInput();

            var idAdd = _userLogic.Add(new Entity.User()
            {
                Name        = name,
                DateOfBirth = GetDateOfBirth(),
            });

            Console.WriteLine($"User Add id: {idAdd}");
        }
示例#21
0
        private void AddUser()
        {
            WriteLine("Enter Name of User");
            var name = GetStringValueInput();

            Guid valueID = userLogic.Add(new User()
            {
                Name        = name,
                DateOfBirth = GetDateOfBirth(),
            });

            ForegroundColor = ConsoleColor.Green;
            WriteLine($"A new user has been added. ID: {valueID}");
            ResetColor();
        }
示例#22
0
 private static void AddUser()
 {
     try
     {
         Console.WriteLine("Enter username:"******"Enter date of birth:");
         DateTime dateOfBirth = DateTime.Parse(Console.ReadLine());
         User     user        = userLogic.Add(userName, dateOfBirth);
         Console.ReadLine();
     }
     catch
     {
         throw new FormatException("Invalid date, try again!");
     }
 }
示例#23
0
        public static String AddUser(string name, DateTime dateOfBirth, byte[] image = null)
        {
            var user = new User
            {
                Name        = name,
                DateOfBirth = dateOfBirth,
            };

            if (image != null)
            {
                user.UserImage = image;
            }

            user = _userLogic.Add(user);

            return($"User has been added to DB. ID = {user.Id}");
        }
示例#24
0
        private static void AddUser(IUserLogic userLogic)
        {
            var user = new User();

            Console.Write("Enter user name: ");
            user.Name = Console.ReadLine();
            Console.Write("Enter user BirthDay(DD/MM/YYYY)): ");
            try
            {
                user.DateOfBirth = DateTime.Parse(Console.ReadLine());
                userLogic.Add(user);
            }
            catch
            {
                Console.WriteLine($"ERROR. Wrong Date! User was not added.{Environment.NewLine}");
            }
        }
示例#25
0
        public IActionResult Register(UserRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                UserDto user = new UserDto
                {
                    DateOfRegistration = DateTime.Now,
                    Email    = model.Email,
                    Password = model.Password,
                    Username = model.Username
                };
                _userRepository.Add(user);
                return(RedirectToAction("details", new { id = user.Id }));
            }

            return(View());
        }
示例#26
0
        private static void AddUser(IUserLogic userLogic, string name, int Year, int Month, int Day)
        {
            DateTime dateTime = new DateTime();

            dateTime = DateTime.Now;
            dateTime = dateTime.AddYears(-Year);
            dateTime = dateTime.AddMonths(-Month);
            dateTime = dateTime.AddDays(-Day);
            User user = new User()
            {
                Name           = name,
                DateOfBirthday = dateTime,
                Age            = Age(dateTime),
            };

            userLogic.Add(user);
        }
示例#27
0
        private static void AddUser()
        {
            Console.WriteLine("Enter username");
            string name = Console.ReadLine();

            Console.WriteLine("Enter birth date");
            string   date  = Console.ReadLine();
            DateTime stamp = new DateTime();

            while (!DateTime.TryParse(date, out stamp))
            {
                Console.WriteLine("Birth date is not valid");
                date = Console.ReadLine();
            }
            int id = userLogic.Add(name, stamp.Date);

            Console.WriteLine($"User with id {id} was added successfully");
        }
示例#28
0
        private static void AddUser(IUserLogic userLogic)
        {
            var user = new User();

            Console.WriteLine();
            while (true)
            {
                try
                {
                    user.Name = ReadName("Enter the name of user: "******"Error: {0}", ex.Message);
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            while (true)
            {
                try
                {
                    user.DateOfBirth = ReadDateTime("Enter date of birth(in format dd-mm-yyyy or dd.mm.yyyy): ");
                    break;
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine();
                    Console.WriteLine("Error: {0}", ex.Message);
                    Console.WriteLine();
                }
            }

            int age = (DateTime.Now - user.DateOfBirth).Days / 365;

            user.Age = age;

            userLogic.Add(user);
            Console.WriteLine();
            Init();
        }
示例#29
0
        private void createUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            User       userToCreate = new User();
            CreateUser createform   = new CreateUser(userToCreate);

            if (createform.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    logic.Add(userToCreate);
                    RefreshUsers();
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                    MessageBox.Show("Couldn't create User", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#30
0
        public static void AddUser()
        {
            try
            {
                string   firstName = ServantClass.AddUserName(FirstNameMessage);
                string   lasttName = ServantClass.AddUserName(LastNameMessage);
                DateTime birthDate = ServantClass.AddUserBirthDate(BirthDateMessage);

                UserLogic.Add(new User(firstName, lasttName, birthDate));

                Console.WriteLine("User successfully added.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot to add user");
                Console.WriteLine(e.Message);

                throw;
            }
        }