public static bool CreateAddressUserScopeIsValid(this AddressUser addressUser)
 {
     return(AssertionConcern.IsSatisfiedBy
            (
                AssertionConcern.AssertNotEmpty(addressUser.Bairro, "O Bairro é obrigatório"),
                AssertionConcern.AssertNotEmpty(addressUser.Cep, "O Cep é obrigatório"),
                AssertionConcern.AssertNotEmpty(addressUser.Number, "O Número é obrigatório")
            ));
 }
 public static bool UpdateAddressUserScopeIsValid(this AddressUser addressUser, UpdateAddressUserCommand command)
 {
     return(AssertionConcern.IsSatisfiedBy
            (
                AssertionConcern.AssertNotEmpty(command.Bairro, "O Bairro é obrigatório"),
                AssertionConcern.AssertNotEmpty(command.Cep, "O Cep é obrigatório"),
                AssertionConcern.AssertNotEmpty(command.Number, "O Número é obrigatório")
            ));
 }
Exemplo n.º 3
0
        public async virtual Task <ActionResult> CompleteInformation(UpdateProfileUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.Invalid), Status = AlertMode.warning
                }));
            }

            var user = await _userManager.FindByIdAsync(User.Identity.GetUserId <int>());

            AddressUser newAddress = new AddressUser();

            newAddress.City       = _cityService.GetById(model.City_Id);
            newAddress.Province   = _provinceService.GetById(model.Province_Id);;
            newAddress.PostalCode = model.PostalCode;
            newAddress.Address    = model.Address;


            if (user.Address != null)
            {
                user.Address.Province   = newAddress.Province;
                user.Address.City       = newAddress.City;
                user.Address.PostalCode = newAddress.PostalCode;
                user.Address.Address    = newAddress.Address;
            }
            else
            {
                user.Address = newAddress;
            }


            user.PhoneNumber   = model.Phone;
            user.Name          = model.Name;
            user.Family        = model.Family;
            user.ReciveMessage = model.ReciveMessage;

            var resultOperation = await _userManager.UpdateAsync(user);

            if (resultOperation.Succeeded)
            {
                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessUpdate), Status = AlertMode.success
                }));
            }
            else
            {
                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate), Status = AlertMode.warning
                }));
            }
        }
Exemplo n.º 4
0
        public AddressUser Create(CreateAddressUserCommand command)
        {
            var address = new AddressUser(command.Cep, command.Logradouro, command.Bairro, command.Localidade, command.Uf, command.Ibge, command.Gia, command.Number, command.Reference, command.IdUser);

            address.Create();
            _repository.Create(address);

            if (Commit())
            {
                return(address);
            }

            return(null);
        }
Exemplo n.º 5
0
        //Creates an address from User input, will change to the final choice later or stay the same
        public async Task <bool> CreateAddress(AddressUser model)
        {
            Address address =
                new Address()
            {
                Address1 = model.Address1,
                Address2 = model.Address2,
                City     = model.City,
                State    = model.State,
                Zip5     = model.Zip5
            };

            _context.Addresses.Add(address);
            return(await _context.SaveChangesAsync() == 1);
        }
Exemplo n.º 6
0
        public async Task <ActionResult <UserDto> > Register(RegisterDto registerDto)
        {
            var user = new AppUser
            {
                DisplayName = registerDto.DisplayName,
                Email       = registerDto.Email,
                UserName    = registerDto.Email
            };

            var result = await _userManager.CreateAsync(user, registerDto.Password);

            var address = new AddressUser
            {
                AppUser   = user,
                AppUserId = user.Id,
                City      = registerDto.City,
                State     = registerDto.State,
                Street    = registerDto.Street,
                Zipcode   = registerDto.Zipcode,
                FirstName = registerDto.FirstName,
                LastName  = registerDto.LastName
            };

            var addressDto = _mapper.Map <AddressUser, AddressUserDto>(address);

            user.AddressUser = address;

            await _userManager.AddToRoleAsync(user, "Member");

            if (!result.Succeeded)
            {
                return(BadRequest(new ApiResponse(400)));
            }

            return(new UserDto
            {
                DisplayName = user.DisplayName,
                Token = _tokenService.CreateToken(user),
                Email = user.Email,
                Role = "Member",
                Address = addressDto
            });
        }
Exemplo n.º 7
0
        public async Task <ActionResult> Create(AddressUser model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            AddressService service = CreateAddressService();

            if (await service.CreateAddress(model))
            {
                return(RedirectToAction($"Choice"));
            }
            ;

            ModelState.AddModelError("", "Address could not be added");

            return(View(model));
        }
Exemplo n.º 8
0
        public IActionResult AddressSet(string del = "0")
        {
            double sumPriceOrder = 0;
            var    items         = shopCart.GetShopItems();

            shopCart.listShopItems = items;
            double Price = 0;

            foreach (var item in shopCart.listShopItems)
            {
                Price += item.price;
            }

            List <OrderDetailRegister> ordersQuantity = context.orderDetailRegisters.Where(i => i.User.email == User.Identity.Name).ToList();

            foreach (var item in ordersQuantity)
            {
                sumPriceOrder += item.price;
            }
            User        user         = MyCabinet.Cabinet.GetUser(User.Identity.Name);
            AddressUser addressUsers = context.addressUsers.Where(i => i.user_id == user.id).ToList().FirstOrDefault();

            IQueryable <Goods> goods = context.Goods;

            objMyCabinet = new MyCabinetViewModel()
            {
                user                 = user,
                ShopCarts            = shopCart,
                Price                = Price,
                quantityOrders       = ordersQuantity.Count(),
                SumPriceOders        = sumPriceOrder,
                OrderDetailRegisters = ordersQuantity.AsQueryable(),
                Goods                = goods,
                AddressUser          = addressUsers
            };
            if (del == "1")
            {
                shopCart.listShopItems.Clear();
                objMyCabinet.ShopCarts.listShopItems.Clear();
                objMyCabinet.Price = 0;
            }
            return(View(objMyCabinet));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Address(MyCabinetViewModel model)
        {
            User        user        = context.Users.Where(i => i.email == User.Identity.Name).FirstOrDefault();
            AddressUser addressUser = context.addressUsers.Where(i => i.user_id == user.id).FirstOrDefault();

            if (model != null)
            {
                addressUser.City     = model.city;
                addressUser.ZiP      = model.zip;
                addressUser.Address1 = model.address1;
                addressUser.Adrress2 = model.address2;


                await context.SaveChangesAsync();

                return(RedirectToAction("AddressSet", "AccountSet"));
            }

            return(RedirectToAction("Index", "Goods/List"));
        }
Exemplo n.º 10
0
        public virtual async Task <ActionResult> UpdateProfile(UpdateProfileUserViewModel userProfile,
                                                               params string[] selectedRole)
        {
            var user = await _userManager.FindByIdAsync(userProfile.Id);

            AddressUser newAddress = new AddressUser();

            newAddress.City       = _cityService.GetById(userProfile.City_Id);
            newAddress.Province   = _provinceService.GetById(userProfile.Province_Id);;
            newAddress.PostalCode = userProfile.PostalCode;
            newAddress.Address    = userProfile.Address;


            if (user.Address != null)
            {
                user.Address.Province   = newAddress.Province;
                user.Address.City       = newAddress.City;
                user.Address.PostalCode = newAddress.PostalCode;
                user.Address.Address    = newAddress.Address;
            }
            else
            {
                user.Address = newAddress;
            }


            user.PhoneNumber   = userProfile.Phone;
            user.ReciveMessage = userProfile.ReciveMessage;
            user.Name          = userProfile.Name;
            user.Family        = userProfile.Family;


            var resultOperation = await _userManager.UpdateAsync(user);

            if (resultOperation.Succeeded)
            {
                var userRoles = await _userManager.GetRolesAsync(user.Id);

                selectedRole = selectedRole ?? new string[] { };

                var result = await _userManager.AddToRolesAsync(user.Id, selectedRole.Except(userRoles).ToArray());

                if (!result.Succeeded)
                {
                    ModelState.AddModelError("", result.Errors.First());
                    return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                    {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate),
                        Status = AlertMode.warning
                    }));
                }
                result = await _userManager.RemoveFromRolesAsync(user.Id, userRoles.Except(selectedRole).ToArray());

                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessUpdate),
                    Status = AlertMode.success
                }));
            }
            else
            {
                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate),
                    Status = AlertMode.warning
                }));
            }
        }
Exemplo n.º 11
0
 public void Delete(AddressUser address)
 {
     _context.AddressUser.Remove(address);
 }
Exemplo n.º 12
0
 public void Update(AddressUser address)
 {
     _context.Entry <AddressUser>(address).State = System.Data.Entity.EntityState.Modified;
 }
Exemplo n.º 13
0
 public void Create(AddressUser address)
 {
     _context.AddressUser.Add(address);
 }