Example #1
0
        public async Task Register(AuthRegister authRegister)
        {
            var identity = Identity.Create(authRegister.UserId, authRegister.Email,
                                           authRegister.Password, authRegister.PasswordKey);

            await _identityRepository.Create(identity);

            var activationCode = ActivationCode.Generate();

            var code = Code.Create(Code.CodeType.ActivationCode, activationCode, identity.Id);

            await _codeRepository.Create(code);

            var activationCodeEmail = new ActivationCodeEmail
            {
                Email          = identity.Email,
                ActivationCode = code.Value,
                FullName       = authRegister.FullName
            };

            _emailPublisher.SendActivationCode(activationCodeEmail);
        }
        public async Task <object> Create([FromBody] CodeViewModel codeViewModel)
        {
            List <Code> listCodes = new List <Code>();

            try
            {
                if (!codeViewModel.IsRange)
                {
                    if (!string.IsNullOrEmpty(codeViewModel.Codes))
                    {
                        using (StringReader reader = new StringReader(codeViewModel.Codes))
                        {
                            string codeNumber = string.Empty;
                            do
                            {
                                Code code = new Code();
                                codeNumber = reader.ReadLine();
                                if (!string.IsNullOrEmpty(codeNumber))
                                {
                                    code.CardId    = codeViewModel.CardId;
                                    code.Number    = codeNumber;
                                    code.IsSold    = false;
                                    code.AddedBy   = codeViewModel.UserId;
                                    code.IsRange   = codeViewModel.IsRange;
                                    code.IsDelete  = false;
                                    code.Timestamp = DateTime.UtcNow;

                                    listCodes.Add(code);
                                }
                            } while (codeNumber != null);
                        }

                        listCodes = _codeRepository.Create(listCodes);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(codeViewModel.CodesFrom) && !string.IsNullOrEmpty(codeViewModel.CodesTo))
                    {
                        long codeFrom = Convert.ToInt64(codeViewModel.CodesFrom);
                        long codeTo   = Convert.ToInt64(codeViewModel.CodesTo);
                        for (long codeNumber = codeFrom; codeNumber <= codeTo; codeNumber++)
                        {
                            Code code = new Code();
                            code.CardId    = codeViewModel.CardId;
                            code.Number    = codeNumber.ToString();
                            code.IsSold    = false;
                            code.AddedBy   = codeViewModel.UserId;
                            code.IsRange   = codeViewModel.IsRange;
                            code.IsDelete  = false;
                            code.Timestamp = DateTime.UtcNow;

                            listCodes.Add(code);
                        }
                        listCodes = _codeRepository.Create(listCodes);
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                error  = ex.Message;
            }

            return(new SingleResponse <List <Code> >
            {
                Message = "Codes created successfully",
                DidError = false,
                ErrorMessage = string.Empty,
                Token = string.Empty,
                Model = listCodes
            });
        }