Esempio n. 1
0
        public async Task <AppResult> CreateAgent(CreateAgentVM model)
        {
            try
            {
                var         phoneNumberUtil = PhoneNumberUtil.GetInstance();
                PhoneNumber phoneNumber     = null;

                if (model.MobileNumber.StartsWith('+'))
                {
                    if (model.MobileNumber.Length < 8)
                    {
                        AppResult.Error(ErrorHandler.GeneralErrorMessage, ResponseMessages.InvalidPhoneNumber);
                    }

                    phoneNumber = phoneNumberUtil.Parse(model.MobileNumber, null);
                }

                if (model.MobileNumber.Length < 8)
                {
                    AppResult.Error(ErrorHandler.GeneralErrorMessage, ResponseMessages.InvalidPhoneNumber);
                }

                phoneNumber = phoneNumberUtil.Parse(model.MobileNumber, model.CountryCode);

                model.MobileNumber = $"{phoneNumber.CountryCode}{phoneNumber.NationalNumber}";


                var resp = await _agentRepository.CreateAgentInDb(model);

                return(ErrorHandler.AgentCreateError.Equals(resp) ? AppResult.Error(resp) : AppResult.Success("Successfully created agent", resp));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.ToString());
                return(AppResult.Error("An error occured", e.ToString()));
            }
        }