Beispiel #1
0
        /// <summary>
        /// Create new user record
        /// </summary>
        /// <param name="user">User model</param>
        public void Create(User user)
        {
            using (var command = new SqlCommand("sp_CreateUser", _connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@UserName", user.UserName);
                command.Parameters.AddWithValue("@LastName", user.LastName);
                command.Parameters.AddWithValue("@Login", user.Login);
                command.Parameters.AddWithValue("@PhoneNumber", user.PhoneNumber);
                command.Parameters.AddWithValue("@Email", user.Email);
                command.Parameters.AddWithValue("@Password", user.Password);
                command.Parameters.AddWithValue("@Role", user.Role);
                command.Parameters.AddWithValue("@Status", user.Status);
                if (user.DriverStatus == null)
                {
                    command.Parameters.AddWithValue("@DriverStatus", DBNull.Value);
                }
                else
                {
                    command.Parameters.AddWithValue("@DriverStatus", user.DriverStatus);

                }
                command.ExecuteNonQuery();
            }
        }
Beispiel #2
0
 public void CreateUser(User user)
 {
     using (var uow = new UnitOfWork(_appConfigConnection))
     {
         uow.UserRepository.Create(user);
     }
 }
Beispiel #3
0
 public static User Map(SqlDataReader record)
 {
     var user = new User
     {
         Id = (int)record["Id"],
         UserName = (string)record["Name"],
         LastName = (string)record["LastName"],
         Login = (string)record["Login"],
         PhoneNumber = (string)record["PhoneNumber"],
         Email = (string)record["Email"],
         Password = (string)record["Password"],
         Role = (int)record["Role"],
         Status = (int)record["Status"],
         DriverStatus = record.IsDBNull(record.GetOrdinal("DriverStatus")) == false
        ? (int?)record["DriverStatus"]
        : default(int?)
     };
     return user;
 }
Beispiel #4
0
 public ActionResult RegisterUser(RegistrationModel registrationModel)
 {
     if (ModelState.IsValid)
     {
         if (!_userBl.IsLoginBooked(registrationModel.Login))
         {
             var user = new User
             {
                 LastName = registrationModel.LastName,
                 Login = registrationModel.Login,
                 PhoneNumber = registrationModel.PhoneNumber,
                 Email = registrationModel.Email,
                 Password = registrationModel.Password,
                 Role = (int) RolesEnum.Client,
                 Status = (int) UserStatusEnum.Active,
                 UserName = registrationModel.FirstName,
                 DriverStatus = null
             };
             _userBl.CreateUser(user);
             //Session["UserFullName"] = user.UserName + " " + user.LastName;
             //Session["UserLogin"] = user.Login;
             FormsAuthentication.SetAuthCookie(user.Login, false);
             return RedirectToAction("Index", "Home");
         }
         else
         {
             ModelState.AddModelError("", "Such login already exists");
         }
     }
     return View(registrationModel);
 }
Beispiel #5
0
 /// <summary>
 /// Check is already user with the same login, but other id
 /// </summary>
 /// <param name="login">String login value</param>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool IsLoginBookedByOtherId(string login, int id)
 {
     using (var command = new SqlCommand("sp_IsLoginBookedByOtherId", _connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@Login", login);
         command.Parameters.AddWithValue("@ID", id);
         var user = new User();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 user = UserMapper.Map(reader);
             }
         }
         if (user.Login == login)
         {
             return true;
         }
     }
     return false;
 }
Beispiel #6
0
 public User GetUserByLogInAndPassword(string login, string password)
 {
     using (var command = new SqlCommand("sp_GetUserByLogInAndPassword", _connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@Login", login);
         command.Parameters.AddWithValue("@Password", password);
         var user = new User();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 user = UserMapper.Map(reader);
             }
         }
         return user;
     }
 }
Beispiel #7
0
 /// <summary>
 /// Get user by id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public User GetUserById(int id)
 {
     using (var command = new SqlCommand("sp_GetUserById", _connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@Id", id);
         var findUser = new User();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var user = UserMapper.Map(reader);
                 findUser = user;
             }
         }
         return findUser;
     }
 }
 public ActionResult GetUserProfile(EditProfileModel editProfileModel)
 {
     if (ModelState.IsValid)
     {
         var user = new User
         {
             LastName = editProfileModel.LastName,
             UserName = editProfileModel.FirstName,
             PhoneNumber = editProfileModel.PhoneNumber,
             Email = editProfileModel.Email,
             Id = editProfileModel.Id,
             Login = editProfileModel.Login,
             Role = (int) RolesEnum.Client,
             Status = (int) UserStatusEnum.Active,
             Password = editProfileModel.Password,
             DriverStatus = null,
         };
         _userBl.UpdateUser(user);
         //Session["UserFullName"] = user.UserName + " " + user.LastName;
         return RedirectToAction("Index", "Home");
     }
     return View(editProfileModel);
 }
        protected void btnSaveEdit_Click(object sender, EventArgs e)
        {
            IAdminBl adminBl = HttpContext.Current.Application.GetContainer().Resolve<IAdminBl>();

            string UserId;
            if (hiddenId.Value != "")
            {
                UserId = hiddenId.Value;
                hiddenId.Value = "";
            }
            else
            {
                UserId = tbxFindOperatorByCategory.Text;
            }

            var updatedUser = new User()
            {
                Id = Convert.ToInt32(UserId),
                UserName = tbxEditOperatorName.Text,
                LastName = tbxEditLastName.Text,
                Login = tbxEditLogin.Text,
                PhoneNumber = tbxEditPhoneNumber.Text,
                Email = tbxEditEmail.Text,
                Password = tbxEditPassword.Text,
                Role = (int) RolesEnum.Operator,
                Status = (int)Enum.Parse(typeof(UserStatusEnum), ddlEditStatus.Text),
                DriverStatus = null
            };
            if (!adminBl.IsLoginBookedByOtherId(updatedUser.Login, updatedUser.Id))
            {
                adminBl.UpdateUser(updatedUser);
                Response.Redirect("~/WebForms/Operators.aspx");
            }
            else
            {
                loginBooked.InnerText = "Login is booked!";
            }
        }
        protected void btnSaveEdit_Click(object sender, EventArgs e)
        {
            IAdminBl adminBl = HttpContext.Current.Application.GetContainer().Resolve<IAdminBl>();

            string UserId;
            if (hiddenId.Value != "")
            {
                UserId = hiddenId.Value;
                hiddenId.Value = "";
            }
            else
            {
                UserId = tbxFindTaxiDriverByCategory.Text;
            }

            var updatedUser = new User()
            {
                Id = Convert.ToInt32(UserId),
                UserName = tbxEditTaxiDriverName.Text,
                LastName = tbxEditLastName.Text,
                Login = tbxEditLogin.Text,
                PhoneNumber = tbxEditPhoneNumber.Text,
                Email = tbxEditEmail.Text,
                Password = tbxEditPassword.Text,
                Role = (int)RolesEnum.Driver,
                Status = (int)Enum.Parse(typeof(UserStatusEnum), ddlEditStatus.Text),
                DriverStatus = (int?)DriverStatusEnum.Free
            };

            if (!adminBl.IsLoginBookedByOtherId(updatedUser.Login, updatedUser.Id))
            {
                adminBl.UpdateUser(updatedUser);

                var updatedCar = new Car()
                {
                    Id = updatedUser.Id,
                    CarBrand = tbxCarBrand.Text,
                    CarYear = tbxCarYear.Text,
                    StartWorkTime = DateTime.Parse(tbxCarStartWorkTime.Text),
                    FinishWorkTime = DateTime.Parse(tbxCarFinishWorkTime.Text),
                    Latitude = tbxCarLatitude.Text,
                    Longitude = tbxCarLongitude.Text
                };
                if (adminBl.IsCarIdBooked(updatedCar.Id))
                {
                    adminBl.UpdateCar(updatedCar);
                }
                else
                {
                    adminBl.CreateCar(updatedCar);
                }

                Response.Redirect("~/WebForms/TaxiDrivers.aspx");
            }
            else
            {
                loginBooked.InnerText = "Login is booked!";
            }
        }