Beispiel #1
0
        //[Authorize(Roles = "Admin, Usuario")]
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var VM = new DetalleCotViewModel();

            VM.Cotizacion = DB.Cotizacion.Include(c => c.Clientes)
                            .FirstOrDefault(c => c.CotizacionId == id);
            VM.DetalleCot = DB.DetalleCot.Include(d => d.Producto)
                            .Where(d => d.CotizacionId == id)
                            .OrderByDescending(c => c.CotizacionId);
            return(View(VM));
        }
Beispiel #2
0
        public ActionResult ProductoFac(DetalleCotViewModel cot, int productoId)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var cotId  = cot.Cotizacion.CotizacionId;
                    var prodId = productoId;
                    var cant   = cot.Cantidad;
                    var ficVeh = cot.FichaVehiculo;
                    var valor  = cot.Valor;
                    var comen  = cot.Comentario;

                    DetalleCot file = new DetalleCot();

                    file.CotizacionId  = cotId;
                    file.ProductoId    = prodId;
                    file.Cantidad      = cant;
                    file.FichaVehiculo = ficVeh;
                    file.Valor         = valor;
                    file.Comentario    = comen;

                    DB.DetalleCot.Add(file);
                    DB.SaveChanges();

                    Decimal monto = DB.DetalleCot
                                    .Where(d => d.CotizacionId == cotId)
                                    .Sum(m => m.Cantidad * m.Valor);
                    Decimal itbis = monto * 0.18m;

                    Cotizacion cotm = DB.Cotizacion.Find(cotId);
                    cotm.TotalFactura = monto;
                    cotm.Itbis        = itbis;
                    DB.SaveChanges();

                    TempData["Status"] = "Upload successful";
                    return(RedirectToAction("ProductoFac", new { cotId = file.CotizacionId }));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(cot));
        }