public void Create(UsersModel user)
        {
            if (string.IsNullOrWhiteSpace(user.Senha))
            {
                throw new Exception("Senha não pode ser nula");
            }

            if (_context.Users.Any(x => x.Login == user.Login))
            {
                throw new Exception("Login \"" + user.Login + "\" já existente");
            }

            //int id = _context.Users.Max(m => m.Id).GetValueOrDefault() + 1;

            string passwordHash, passwordSalt;

            CreatePasswordHash(user.Senha, out passwordHash, out passwordSalt);

            //user.Id = id;
            user.Senha = passwordHash;
            user.Salt  = passwordSalt;
            user.Role  = "user";

            _context.Users.Add(user);
            _context.SaveChanges();
        }
        public ActionResult Create(compraCine compraCine)
        {
            double  subtotal             = 0;
            decimal cargoServicio        = 0;
            decimal descuento            = 0;
            decimal total                = 0;
            double  total2               = 0;
            decimal ticke_Ninos_Precio   = 0;
            decimal ticke_Recular_Precio = 0;
            int     total_Tickes         = 0;


            if (compraCine != null)
            {
                var ticket = db.ticket.Find(compraCine.idTicket);
                /*Valor de los tickets*/
                ticke_Ninos_Precio   = compraCine.cantidadNinos * ticket.precioNino;
                ticke_Recular_Precio = compraCine.cantidadNinos * ticket.precioRegular;

                /*Valor del Subtotal*/
                subtotal = Convert.ToInt32(ticke_Ninos_Precio + ticke_Recular_Precio);
                total    = Convert.ToDecimal(subtotal);
                /*Cantidad total de tickes*/
                total_Tickes = compraCine.cantidadNinos + compraCine.cantidadRegular;

                /*Validar si hay descuento*/
                if (total_Tickes >= ticket.cantidaTicketsdDescuento)
                {
                    descuento = Convert.ToDecimal(subtotal * 0.2);
                }

                total = total - descuento;

                total2        = Convert.ToDouble(total);
                cargoServicio = Convert.ToDecimal(total2 * 0.13);
                total         = total + cargoServicio;
            }



            if (ModelState.IsValid)
            {
                db.compraCine.Add(compraCine);

                compraCine.descuento     = descuento;
                compraCine.total         = total;
                compraCine.cargoServicio = cargoServicio;
                db.SaveChanges();
                TempData["mensaje"] = "Guardado con éxito.";
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["mensaje"] = "No guardodo.";
            }

            ViewBag.idTicket = new SelectList(db.ticket, "idTicket", "nombrePelicula", compraCine.idTicket);
            return(View(compraCine));
        }
Exemple #3
0
 public ActionResult Editar(ticket ticket)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticket).State = EntityState.Modified;
         db.SaveChanges();
         TempData["mensaje"] = "Editado con éxito.";
         return(RedirectToAction("Index"));
     }
     else
     {
         TempData["mensaje"] = "NO Editado.";
     }
     return(View("Edit", ticket));
 }
        public async Task <IActionResult> RegisterPassword(RegisterPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.Users
                       .SingleOrDefaultAsync(x => x.UserName == model.Email);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToAction(nameof(Login)));
            }

            var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

            if (result.Succeeded)
            {
                user.EmailConfirmed = true;
                _context.SaveChanges();

                var resultLogin = Microsoft.AspNetCore.Identity.SignInResult.Failed;

                if (resultLogin.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction(nameof(Login)));
                }
            }

            AddErrors(result);
            return(View(model));
        }