コード例 #1
0
        public ActionResult Create(FormCollection form)
        {
            try
            {
                CotizacionMessage cotMessage = new CotizacionMessage(); ;
                if (ModelState.IsValid)
                {
                    var detalle = Newtonsoft.Json.JsonConvert.DeserializeObject<ModelCotiza>(form["datainfo"]);

                    var cotDet = new List<COD_CotizacionDetalle>();

                    COT_Cotizaciones cot = new COT_Cotizaciones()
                    {
                        COT_Celular = detalle.celular,
                        COT_Email = detalle.correo,
                        COT_Descripcion = detalle.descripcion,
                        COT_Mensaje = detalle.mensaje,
                        COT_Telefono = detalle.telefono,
                        COT_Nombre = detalle.nombre,
                        COT_Fecha = System.DateTime.Now,
                        STS_Id = 1,
                    };
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        db.COT_Cotizaciones.Add(cot);

                        var savecot = db.SaveChanges<COT_Cotizaciones>(cot);
                        detalle.cotiza.ForEach(c => cotDet.Add(new COD_CotizacionDetalle
                        {
                            COD_Cantidad = int.Parse(c.prodqty),
                            PRO_Id = int.Parse(c.prodid),
                            COD_Id = savecot.COT_Id
                        }));
                        cotDet.ForEach(c => db.SaveChanges<COD_CotizacionDetalle>(c));
                        transaction.Complete();
                        cotMessage = new CotizacionMessage { Cotizacion = detalle, Id = savecot.COT_Id };
                    }
                    Task.Factory.StartNew(() =>
                    {
                        SendMessage(cotMessage);
                    });
                    return Json(new { success = true });
                }
                return null;
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return Json(new { success = "validation" });
            }

            catch (Exception ex)
            {
                return Json(new { success = false });
            }


        }
コード例 #2
0
 public ActionResult Edit(COT_Cotizaciones cot_cotizaciones)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cot_cotizaciones).State = EntityState.Modified;
         db.SaveChanges();
         if (Request.IsAjaxRequest())
         {
             return Json(new { redirectToUrl = Url.Action("Index", "Cotiza") });
         }
         return RedirectToAction("Index");
     }
     ViewBag.STS_Id = new SelectList(db.STS_Status, "STS_Id", "STS_Descripcion", cot_cotizaciones.STS_Id);
     return View(cot_cotizaciones);
 }