Пример #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 Edit([Bind(Include = "ParticipanteId,Nombre,Apellido,Correo,Estado,EventoId")] Participante participante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(participante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Participantes", new { @id = participante.EventoId }));
     }
     ViewBag.EventoId = new SelectList(db.Eventos, "EventoId", "Nombre", participante.EventoId);
     return(View(participante));
 }
Пример #3
0
 public ActionResult Edit([Bind(Include = "EntradaId,Nombre,Precio,Cupo,CantidadMinima,CantidadMaxima,Descripcion,FechaLimite,EventoId")] Entrada entrada)
 {
     if (ModelState.IsValid)
     {
         db.Entry(entrada).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { @id = entrada.EventoId }));
     }
     return(View(entrada));
 }
Пример #4
0
        public ActionResult Edit(CrearEventoModelo modelo)
        {
            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)
            {
                db.Entry(modelo.Contacto).State = EntityState.Modified;
                db.SaveChanges();

                modelo.Evento.ContactoId = modelo.Contacto.ContactoId;

                db.Entry(modelo.Evento).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details", new { @id = modelo.Evento.EventoId }));
            }
            return(View(modelo));
        }