Esempio n. 1
0
        public void CanCreatePayer()
        {
            var provider = BuildProvider();
            var retValue = _repository.Create(provider);

            Assert.AreEqual(retValue, 1);
        }
Esempio n. 2
0
        public async Task <CommandResult> Create(ProviderModel request)
        {
            var validate = new CommandResult(true, "Cadastro Aprovado!");

            if (validate.Success)
            {
                if (request.PersonType == 0)
                {
                    return(new CommandResult(false, "Preencher os campos de RG, CPF, e Data de Nascimento para cadastro de pessoas físicas."));
                }

                int age = DateTime.Now.Subtract(request.DateBirth).Days / 365;

                if (age < 18)
                {
                    if (request.State == 0)
                    {
                        return(new CommandResult(false, "Para cadastro de pessoas físicas do estado do Paraná somente maiores de 18 anos."));
                    }
                }

                var provider = new Provider(request.Name, request.Create_At, request.CPF, request.RG, request.DateBirth, request.CNPJProvider, request.State,
                                            request.PersonType, request.ContactNumber);
                await _providerRepository.Create(provider);

                return(new CommandResult(true, "Cadastro realizado com sucesso"));
            }

            return(new CommandResult(false, "Não foi possível concluir o cadastro. Confira os dados e tente novamente."));
        }
Esempio n. 3
0
        public async Task <IActionResult> RegisterProvider(RegisterProviderViewModel vm)
        {
            //We added validation
            //So that is where isValid comes into action
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName    = vm.Username,
                    PhoneNumber = vm.Phone,
                    Email       = vm.Email
                };

                //save to db
                //you don't want to do it in your main thread
                //this method needs to be an async method
                IdentityResult result = await _userManagerService.CreateAsync(user, vm.Password);

                if (result.Succeeded)
                {
                    if (!await _userManagerService.IsInRoleAsync(user, "Provider"))
                    {
                        await _userManagerService.AddToRoleAsync(user, "Provider");
                    }

                    IdentityUser specificUser = await _userManagerService.FindByNameAsync(user.UserName);

                    Provider newProvider = new Provider
                    {
                        UserId      = specificUser.Id,
                        DisplayName = vm.DisplayName,
                        ABN         = vm.ABN
                    };

                    _providerRepo.Create(newProvider);


                    //--------======= SMS Notification ========-----------

                    string smsContent = "Welcome to Grande Travel, " + newProvider.DisplayName + "!";

                    await _smsService.SendSmsAsync(user.PhoneNumber, smsContent);


                    return(RedirectToAction("Index", "Packages"));
                    //return RedirectToAction("Login", "Account");
                }
                else
                {
                    foreach (var err in result.Errors)
                    {
                        //ModelState.AddModelError("" , "error");
                        ModelState.AddModelError("", err.Description);
                    }
                }
            }

            return(View(vm));
        }
Esempio n. 4
0
 public void Create(Provider provider)
 {
     provider.CreatedAt = DateTime.Now;
     if (provider.Images == null)
     {
         provider.Images = new[] { new Image {
                                       Url = Constants.DefaultProviderImage
                                   } }
     }
     ;
     _providerRepository.Create(provider);
     _contextProvider.CommitChanges();
 }
        public ActionResult Post([FromBody] ProviderForCreate providerDto)
        {
            if (providerDto == null)
            {
                return(BadRequest("Invalid request"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid request"));
            }
            var providerEntity = _mapper.Map <Provider>(providerDto);

            if (providerEntity == null)
            {
                return(BadRequest("Invalid request"));
            }
            var retVal = _repository.Create(providerEntity);

            if (retVal != 1)
            {
                return(Ok("failed to save data, kindly verify your inputs"));
            }
            return(Ok("new provider created succesfully"));
        }
Esempio n. 6
0
 public void Create(Provider input)
 {
     _providerRepo.Create(input);
 }