示例#1
0
        public ActionResult FinalizarCompra()
        {
            using (var db = new EventorDbContext())
            {
                var items = (List <Item>)Session["Items"];

                if (items != null)
                {
                    decimal total = 0;
                    foreach (var item in items)
                    {
                        total += item.Subtotal;
                    }

                    var pedido = new Pedido()
                    {
                        FechaHora = DateTime.Now,
                        UserName  = User.Identity.GetUserName(),
                        Total     = total
                    };

                    db.Pedidos.Add(pedido);
                    db.SaveChanges();

                    db.Entry(pedido).State = EntityState.Detached;

                    int id = int.Parse(db.Pedidos
                                       .OrderByDescending(p => p.FechaHora)
                                       .Select(r => r.PedidoId)
                                       .First().ToString());

                    var          pedidoAgregado = db.Pedidos.Find(id);
                    Participante participante   = null;
                    var          user           = User.Identity.GetUserName();

                    foreach (var item in items)
                    {
                        pedidoAgregado.Items.Add(new Item
                        {
                            Cantidad  = item.Cantidad,
                            EntradaId = item.EntradaId,
                            PedidoId  = id,
                            Subtotal  = item.Subtotal,
                            Precio    = item.Precio
                        });

                        participante                 = db.Participantes.Where(p => p.EventoId == item.Entrada.EventoId && p.Correo == user).Single();
                        participante.Estado          = Estado.Confirmado;
                        db.Entry(participante).State = EntityState.Modified;
                    }
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
        }
示例#2
0
        public ActionResult Create([Bind(Include = "EntradaId,Nombre,Precio,Cupo,CantidadMinima,CantidadMaxima,Descripcion,FechaLimite,EventoId")] Entrada entrada)
        {
            if (ModelState.IsValid)
            {
                db.Entradas.Add(entrada);
                db.SaveChanges();
                return(RedirectToAction("Index", new { @id = entrada.EventoId }));
            }

            ViewBag.EventoId = entrada.EventoId;
            return(View(entrada));
        }
示例#3
0
        public ActionResult Create(CrearEventoModelo modelo)
        {
            var contacto = modelo.Contacto;
            var evento   = modelo.Evento;

            if (modelo.Evento.Inicio.CompareTo(modelo.Evento.Final) > 0)
            {
                ModelState.AddModelError("", "La fecha de inicio debe ser menor que la fecha final");
            }

            if (ModelState.IsValid)
            {
                evento.Contacto = contacto;
                evento.UserName = User.Identity.GetUserName();
                db.Eventos.Add(evento);
                db.SaveChanges();
                return(RedirectToAction("Details", new { @id = evento.EventoId }));
            }
            return(View(modelo));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "ParticipanteId,Nombre,Apellido,Correo,Estado,EventoId")] Participante participante)
        {
            if (ModelState.IsValid)
            {
                db.Participantes.Add(participante);
                db.SaveChanges();
                SendEmail(participante.ParticipanteId, participante.EventoId);
                return(RedirectToAction("Index", new { @id = participante.EventoId }));
            }

            ViewBag.EventoId = new SelectList(db.Eventos, "EventoId", "Nombre", participante.EventoId);
            return(View(participante));
        }