Пример #1
0
        public ActionResult DeleteMedicamento(MedicamentoOrder m)
        {
            var MedicamentoId = int.Parse(Request["MedicamentoId"]);

            var orderView = Session["orderView"] as OrderView;

            m = orderView.medicamentoOrder.Find(x => x.MedicamentoId == MedicamentoId);

            orderView.MontoTotal -= m.Precio * m.Cantidad;
            orderView.medicamentoOrder.Remove(m);

            ViewBag.MessageSuccess = "Se elimino producto";
            return(View("NewOrder", orderView));
        }
Пример #2
0
        public ActionResult EditMedicamento(MedicamentoOrder m, int Cantidad)
        {
            var MedicamentoId = int.Parse(Request["MedicamentoId"]);

            var orderView = Session["orderView"] as OrderView;

            var medicamento = db.Medicamento.Find(MedicamentoId);

            m = orderView.medicamentoOrder.Find(x => x.MedicamentoId == medicamento.MedicamentoId);

            if (MedicamentoId < 1)
            {
                ViewBag.MessageError = "Seleccione un producto";
                return(View(m));
            }
            if (medicamento == null)
            {
                ViewBag.MessageError = "Producto no existe";
                return(View(m));
            }
            if (Cantidad <= 0)
            {
                ViewBag.MessageError = "Ingrese una cantidad mayor a 0";
                return(View(m));
            }
            if (medicamento.Stock < Cantidad)
            {
                ViewBag.MessageError = "Medicamento no tiene stock suficiente";
                return(View(m));
            }
            if (medicamento.Stock == 0)
            {
                ViewBag.MessageError = "Medicamento no tiene existencias";
                return(View(m));
            }

            orderView.MontoTotal -= medicamento.Precio * m.Cantidad;
            m.Cantidad            = Cantidad;
            m.SubTotal            = medicamento.Precio * Cantidad;
            orderView.MontoTotal += medicamento.Precio * Cantidad;

            ViewBag.MessageSuccess = "Se edito producto";
            return(View("NewOrder", orderView));
        }
Пример #3
0
        public ActionResult AddMedicamento(MedicamentoOrder m, int Cantidad)
        {
            ViewBag.Medicamentos = new SelectList(db.Medicamento, "MedicamentoId", "MedicamentoEspecie");
            var MedicamentoId = int.Parse(Request["MedicamentoId"]);
            var orderView     = Session["orderView"] as OrderView;

            try
            {
                var medicamento = db.Medicamento.Find(MedicamentoId);
                if (MedicamentoId < 1)
                {
                    ViewBag.MessageError = "Seleccione un producto";
                    return(View(m));
                }
                if (medicamento == null)
                {
                    ViewBag.MessageError = "Producto no existe";
                    return(View(m));
                }
                if (Cantidad <= 0)
                {
                    ViewBag.MessageError = "Ingrese una cantidad mayor a 0";
                    return(View(m));
                }
                if (medicamento.Stock < Cantidad)
                {
                    ViewBag.MessageError = "Medicamento no tiene stock suficiente";
                    return(View(m));
                }
                if (medicamento.Stock == 0)
                {
                    ViewBag.MessageError = "Medicamento no tiene existencias";
                    return(View(m));
                }

                m = orderView.medicamentoOrder.Find(x => x.MedicamentoId == MedicamentoId);

                if (m == null)
                {
                    m = new MedicamentoOrder
                    {
                        Nombre             = medicamento.Nombre,
                        DescripcionEspecie = medicamento.Especie.Descripcion,
                        DescripcionTipo    = medicamento.TipoMedicamento.Descripcion,
                        MedicamentoId      = medicamento.MedicamentoId,
                        SubTotal           = medicamento.Precio * Cantidad,
                        Precio             = medicamento.Precio,
                        Cantidad           = Cantidad
                    };
                    orderView.medicamentoOrder.Add(m);
                    orderView.MontoTotal += m.SubTotal;
                }
                else
                {
                    m.Cantidad           += Cantidad;
                    m.SubTotal           += medicamento.Precio * Cantidad;
                    orderView.MontoTotal += medicamento.Precio * Cantidad;
                }

                ViewBag.MessageSuccess = "Se agrego producto";
                return(View("NewOrder", orderView));
            }
            catch (NullReferenceException)
            {
                orderView = new OrderView();
                orderView.medicamentoOrder = new List <MedicamentoOrder>();
                Session["orderView"]       = orderView;
                ViewBag.MessageError       = "Ya puede agregar detalle";
                return(View(m));
            }
            catch (Exception e)
            {
                ViewBag.MessageError = e.Message;
                return(View(m));
            }
        }