Пример #1
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 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 CheckPin(CheckPinDtoCommand checkPinDto)
        {
            string email = checkPinDto.Email.ToLower();
            string pin   = checkPinDto.Pin;

            int storeId = _storeRepository.GetStoreIdByEmail(email);

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

            UserEntity userEntity = _userRepository.GetUserByEmialAndPin(storeId, pin);

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