Beispiel #1
0
        public IActionResult UserDelete(string nameUser)
        {
            try
            {
                string email = HttpContext.Session.GetString("Email");
                if (String.IsNullOrEmpty(email))
                {
                    return(RedirectToAction("Index", "Register"));
                }

                email = email.ToLower();
                bool isEmail = _authService.ChechEmail(email);
                if (!isEmail)
                {
                    return(RedirectToAction("Error", "Management", new { message = "E-Mail ไม่มีอยู่ในระบบโปรดลงทะเบียนใหม่" }));
                }

                CheckNameUserDtoCommand checkNameUser = new CheckNameUserDtoCommand()
                {
                    Email    = email,
                    NameUser = nameUser
                };
                bool isName = _authService.DeleteNameUser(checkNameUser);
                if (!isName)
                {
                    return(RedirectToAction("Error", "User", new { message = "ไม่สามารถลบพนักงานได้" }));
                }
                return(RedirectToAction("SuccessPage", "User", new { message = "ลบพนักงานสำเร็จ" }));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : " + e.Message);
                return(RedirectToAction("Index", "Register"));
            }
        }
Beispiel #2
0
        public IActionResult CallEditUser(string nameUser, string pin, string oldUser)
        {
            try
            {
                string email = HttpContext.Session.GetString("Email");
                if (String.IsNullOrEmpty(email))
                {
                    return(RedirectToAction("Index", "Register"));
                }

                email = email.ToLower();
                bool isEmail = _authService.ChechEmail(email);
                if (!isEmail)
                {
                    return(RedirectToAction("Error", "Management", new { message = "E-Mail ไม่มีอยู่ในระบบโปรดลงทะเบียนใหม่" }));
                }

                CheckPinDtoCommand checkPinDto = new CheckPinDtoCommand()
                {
                    Email = email,
                    Pin   = pin
                };
                bool isPin = _authService.CheckPin(checkPinDto);
                if (isPin)
                {
                    return(RedirectToAction("Error", "Management", new { message = "Pin นี้ถูกใช้งานในร้านค้านี้เรียบร้อย" }));
                }

                CheckNameUserDtoCommand checkNameUser = new CheckNameUserDtoCommand()
                {
                    Email    = email,
                    NameUser = nameUser
                };
                bool isName = _authService.ChechNameUser(checkNameUser);
                if (isName)
                {
                    return(RedirectToAction("Error", "Management", new { message = "ชื่อพนักงานคนนี้ถูกใช้งานในร้านค้านี้เรียบร้อย" }));
                }

                EditUserInStoreDtoCommand command = new EditUserInStoreDtoCommand()
                {
                    Email    = email,
                    OldUser  = oldUser,
                    NameUser = nameUser,
                    Pin      = pin
                };
                bool isRegisUser = _authService.EditUserInStore(command);
                if (!isRegisUser)
                {
                    return(RedirectToAction("Error", "User", new { message = "ไม่สามารถแก้ไขพนักงานได้" }));
                }
                return(RedirectToAction("SuccessPage", "User", new { message = "แก้ไขพนักงานสำเร็จ" }));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : " + e.Message);
                return(RedirectToAction("Index", "Register"));
            }
        }
        public bool DeleteNameUser(CheckNameUserDtoCommand checkNameUser)
        {
            string email = checkNameUser.Email.ToLower();
            string user  = checkNameUser.NameUser;

            int storeId = _storeRepository.GetStoreIdByEmail(email);

            if (storeId == default || storeId == 0)
            {
                return(false);
            }

            return(_userRepository.DeleteUserByEmialAndUser(storeId, user));
        }
        public IActionResult CallAPIRegisUser(string email, string nameUser, string pin)
        {
            email = email.ToLower();
            bool isEmail = _authService.ChechEmail(email);

            if (!isEmail)
            {
                return(RedirectToAction("Error", "Management", new { message = "E-Mail ไม่มีอยู่ในระบบโปรดลงทะเบียนใหม่" }));
            }

            CheckPinDtoCommand checkPinDto = new CheckPinDtoCommand()
            {
                Email = email,
                Pin   = pin
            };
            bool isPin = _authService.CheckPin(checkPinDto);

            if (isPin)
            {
                return(RedirectToAction("Error", "Management", new { message = "Pin นี้ถูกใช้งานในร้านค้านี้เรียบร้อย" }));
            }

            CheckNameUserDtoCommand checkNameUser = new CheckNameUserDtoCommand()
            {
                Email    = email,
                NameUser = nameUser
            };
            bool isName = _authService.ChechNameUser(checkNameUser);

            if (isName)
            {
                return(RedirectToAction("Error", "Management", new { message = "ชื่อพนักงานคนนี้ถูกใช้งานในร้านค้านี้เรียบร้อย" }));
            }

            RegisterUserInStoreDtoCommand command = new RegisterUserInStoreDtoCommand()
            {
                Email    = email,
                NameUser = nameUser,
                Pin      = pin
            };
            bool isRegisUser = _authService.RegisterUserInStore(command);

            if (!isRegisUser)
            {
                return(RedirectToAction("Error", "Management", new { message = "ไม่สามารถเพิ่มพนักงานได้" }));
            }
            return(RedirectToAction("SuccessPage", "Management", new { message = "เพิ่มพนักงานสำเร็จ" }));
        }
        public bool ChechNameUser(CheckNameUserDtoCommand checkNameUser)
        {
            string email = checkNameUser.Email.ToLower();
            string user  = checkNameUser.NameUser;

            int storeId = _storeRepository.GetStoreIdByEmail(email);

            if (storeId == default || storeId == 0)
            {
                return(false);
            }

            UserEntity userEntity = _userRepository.GetUserByEmialAndUser(storeId, user);

            if (userEntity == default)
            {
                return(false);
            }
            return(true);
        }