Ejemplo n.º 1
0
        public ActionResult Edit(AdminUserViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                FlashMessage.Error("Preencha todos os campos");
                return(View(nameof(Edit), viewModel));
            }

            var user = UserManager.FindById(viewModel.Id);

            user.FirstName = viewModel.FirstName;
            user.LastName  = viewModel.LastName;
            user.Email     = viewModel.Email;
            user.UserName  = viewModel.Email;

            var result = UserManager.Update(user);

            if (result.Succeeded)
            {
                FlashMessage.Success("Alterado com sucesso");
                return(RedirectToAction(nameof(Index), "AdminUser"));
            }

            FlashMessage.Error(result.Errors.FirstOrDefault());
            return(View(nameof(Edit), viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(FornecedorUserViewModel viewModel)
        {
            if (ModelState.IsValid && viewModel.IsValid)
            {
                var user = UserManager.FindById(viewModel.Id);

                user.FirstName    = viewModel.FirstName;
                user.LastName     = viewModel.LastName;
                user.Email        = viewModel.Email;
                user.UserName     = viewModel.Email;
                user.CpfCnpj      = viewModel.Cnpj;
                user.PhoneNumber  = viewModel.PhoneNumber;
                user.PhantasyName = viewModel.PhantasyName;
                user.Site         = viewModel.Site;

                var result = UserManager.Update(user);
                if (result.Succeeded)
                {
                    FlashMessage.Success("Salvo com sucesso");
                    return(RedirectToAction(nameof(Index), "FornecedorUser"));
                }

                FlashMessage.Error(result.Errors.FirstOrDefault());
            }

            if (viewModel.Errors.Any())
            {
                FlashMessage.Error(viewModel.Errors.Any()
                    ? viewModel.Errors.FirstOrDefault()
                    : "O formulário não está valido");
            }

            return(View(nameof(Edit), viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = SignInManager.PasswordSignIn(model.Email, model.Password, model.RememberMe, false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                FlashMessage.Info("Usuário bloqueado, contate o administrador do sistema");
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, model.RememberMe }));

            default:
                FlashMessage.Error("Usuário ou senha inválidos");
                return(View(model));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Register(AdminUserViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                FlashMessage.Error("Preencha todos os campos");
                return(View(nameof(Register), viewModel));
            }

            var user = new ApplicationUser
            {
                FirstName = viewModel.FirstName,
                LastName  = viewModel.LastName,
                Email     = viewModel.Email,
                UserName  = viewModel.Email
            };

            var result = UserManager.Create(user, "Admin@1234");

            if (result.Succeeded)
            {
                UserManager.AddToRole(user.Id, nameof(Roles.Administrador));

                FlashMessage.Success("Cadastrado com sucesso");

                return(RedirectToAction(nameof(Index), "AdminUser"));
            }

            FlashMessage.Error(result.Errors.FirstOrDefault());
            return(View(nameof(Register), viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult Delete(string id)
        {
            try
            {
                _wishListService.Delete(id);

                FlashMessage.Success("Excluido com sucesso");
            }
            catch (Exception e)
            {
                FlashMessage.Error(e.Message);
            }
            return(RedirectToAction(nameof(Index), "WishList"));
        }
Ejemplo n.º 6
0
        public ActionResult Unlock(string id)
        {
            var user = UserManager.FindById(id);

            user.LockoutEndDateUtc = DateTime.MaxValue;

            var result = UserManager.Update(user);

            if (result.Succeeded)
            {
                FlashMessage.Success("Desbloqueado com sucesso");
            }
            else
            {
                FlashMessage.Error(result.Errors.FirstOrDefault());
            }

            return(RedirectToAction(nameof(Index), "FornecedorUser"));
        }
Ejemplo n.º 7
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid && model.IsValid)
            {
                var birthDate = Convert.ToDateTime(model.BirthDate);
                var user      = new ApplicationUser
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    CpfCnpj     = model.Cpf,
                    PhoneNumber = model.PhoneNumber,
                    BirthDate   = birthDate,
                    Gender      = model.Gender
                };
                var result = UserManager.Create(user, model.Password);
                UserManager.AddToRole(user.Id, "Cliente");

                if (result.Succeeded)
                {
                    SignInManager.SignIn(user, false, false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Dashboard"));
                }

                FlashMessage.Error(result.Errors.FirstOrDefault());
            }
            else
            {
                FlashMessage.Error(model.Errors.Any() ? model.Errors.FirstOrDefault() : "Ocorreu um erro ao cadastrar");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult Insert(ProductViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    FlashMessage.Warning("Formulário incompleto");
                    return(View(nameof(Insert), viewModel));
                }

                // store Id é o ID do Fornecedor logado
                var storeId = User.Identity.GetUserId();

                var product = new Product
                {
                    Name        = viewModel.Name,
                    Description = viewModel.Description,
                    BoxDepth    = Convert.ToDecimal(viewModel.BoxDepth),
                    BoxWidth    = Convert.ToDecimal(viewModel.BoxWidth),
                    BoxHeight   = Convert.ToDecimal(viewModel.BoxHeight),
                    Price       = Convert.ToDecimal(viewModel.Price.Replace(".", string.Empty).Replace(",", ".")),
                    Brand       = viewModel.Brand,
                    CategoryId  = viewModel.Category,
                    Store       = storeId,
                    Unit        = Convert.ToDecimal(viewModel.Unit),
                    Weight      = Convert.ToDecimal(viewModel.Weight),
                    Measure     = viewModel.Measure
                };

                _productService.Insert(product);
                FlashMessage.Success("Cadastrado com sucesso");

                return(RedirectToAction(nameof(Index), "Product"));
            }
            catch (Exception e)
            {
                FlashMessage.Error(e.Message);
                return(View(nameof(Insert), viewModel));
            }
        }
Ejemplo n.º 9
0
        public ActionResult MassInsert(HttpPostedFileBase file)
        {
            try
            {
                if (file == null)
                {
                    FlashMessage.Error("Aconteceu um erro ao subir o arquivo");
                    return(RedirectToAction(nameof(MassInsert), "Product"));
                }

                var fileExtension = Path.GetExtension(file.FileName);
                if (fileExtension?.ToLower() != ".xlsx")
                {
                    FlashMessage.Warning("Arquivo inválido");
                    return(RedirectToAction(nameof(MassInsert), "Product"));
                }

                var fornecedorId = User.Identity.GetUserId();
                var fileName     = $"{Guid.NewGuid().ToString()}_{fornecedorId}.xlsx";


                var path = Path.Combine(Server.MapPath("~/App_Data"), fileName);
                file.SaveAs(path);

                _productService.MassInsert(path, fornecedorId);

                // apaga o arquivo
                new FileInfo(path).Delete();

                FlashMessage.Success("Importado com sucesso");
                return(RedirectToAction(nameof(Index), "Product"));
            }
            catch (Exception e)
            {
                FlashMessage.Error(e.Message);
                return(RedirectToAction(nameof(MassInsert), "Product"));
            }

            return(View());
        }
Ejemplo n.º 10
0
        public ActionResult Register(FornecedorUserViewModel viewModel)
        {
            if (ModelState.IsValid && viewModel.IsValid)
            {
                var user = new ApplicationUser
                {
                    Email        = viewModel.Email,
                    FirstName    = viewModel.FirstName,
                    LastName     = viewModel.LastName,
                    UserName     = viewModel.Email,
                    CpfCnpj      = Mask.RemoveMask(viewModel.Cnpj),
                    PhoneNumber  = viewModel.PhoneNumber,
                    PhantasyName = viewModel.PhantasyName,
                    Site         = viewModel.Site
                };


                var result = UserManager.Create(user, "Fornecedor@1234");
                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, nameof(Roles.Fornecedor));

                    FlashMessage.Success("Cadastrado com sucesso");
                    return(RedirectToAction(nameof(Index), "FornecedorUser"));
                }

                FlashMessage.Error(result.Errors.FirstOrDefault());
            }

            if (viewModel.Errors.Any())
            {
                FlashMessage.Error(viewModel.Errors.Any()
                    ? viewModel.Errors.FirstOrDefault()
                    : "O formulário não está valido");
            }

            return(View(nameof(Register), viewModel));
        }
Ejemplo n.º 11
0
        public ActionResult Edit(ProductViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    FlashMessage.Warning("Formulário incompleto");
                    return(View(nameof(Edit), viewModel));
                }


                var product = new Product
                {
                    Name        = viewModel.Name,
                    Description = viewModel.Description,
                    BoxDepth    = Convert.ToDecimal(viewModel.BoxDepth),
                    BoxWidth    = Convert.ToDecimal(viewModel.BoxWidth),
                    BoxHeight   = Convert.ToDecimal(viewModel.BoxHeight),
                    Price       = Convert.ToDecimal(viewModel.Price.Replace(".", string.Empty).Replace(",", ".")),
                    Brand       = viewModel.Brand,
                    CategoryId  = viewModel.Category,
                    Unit        = Convert.ToDecimal(viewModel.Unit),
                    Weight      = Convert.ToDecimal(viewModel.Weight),
                    Measure     = viewModel.Measure
                };

                _productService.Update(product);
                FlashMessage.Success("Alterado com sucesso");

                return(RedirectToAction(nameof(Index), "Product"));
            }
            catch (Exception e)
            {
                FlashMessage.Error(e.Message);
                return(View(nameof(Edit), viewModel));
            }
        }