public JsonResult Create(int IdCliente, double diasEntrega, CotizacionFuncion[] CotizacionFuncion) { try { String mensaje = ""; idCotizacion = db.Cotizacion.Max(w => w.IdCotizacion) + 1; try { using (var dbContext = new ConfortexEntities()) { dbContext.sp_GestionarCotizacion(idCotizacion, IdCliente, clsReferencias.EnBorrador, clsReferencias.INSERT, diasEntrega); } using (var dbContext = new ConfortexEntities()) { dbContext.sp_AsignarUsuarioAudit(User.Identity.GetUserName()); } } catch (Exception ex) { mensaje = new clsException(ex).Message(); idCotizacion = -1; } if (idCotizacion != -1) { for (int i = 0; i < CotizacionFuncion.Length; i++) { CotizacionFuncion[i].IdCotizacion = idCotizacion; CotizacionFuncion[i].FechaCreacion = System.DateTime.Now; db.CotizacionFuncion.Add(CotizacionFuncion[i]); } db.SaveChanges(); } else { return(Json(new { Message = mensaje })); } return(Json(new { Message = clsReferencias.Exito })); } catch (Exception ex) { return(Json(new { Message = new clsException(ex).Message() })); } }
public JsonResult Edit(int IdCotizacion, double diasEntrega, int IdCliente, CotizacionFuncion[] CotizacionFuncion) { try { idCotizacion = IdCotizacion; String mensaje = ""; try { using (var dbContext = new ConfortexEntities()) { dbContext.sp_GestionarCotizacion(idCotizacion, IdCliente, clsReferencias.Ignore_Estate, clsReferencias.UPDATE, diasEntrega); } using (var dbContext = new ConfortexEntities()) { dbContext.sp_AsignarUsuarioAudit(User.Identity.GetUserName()); } } catch (Exception ex) { mensaje = new clsException(ex).Message(); idCotizacion = -1; } if (IdCotizacion != -1) { List <CotizacionFuncion> cotizaciones = db.CotizacionFuncion.Where(w => w.IdCotizacion == idCotizacion).ToList(); for (int i = 0; i < CotizacionFuncion.Length; i++) { CotizacionFuncion cf = db.CotizacionFuncion.Find(new object[] { CotizacionFuncion[i].IdCotizacion, CotizacionFuncion[i].NombreFuncion }); if (cf == null) { CotizacionFuncion[i].IdCotizacion = idCotizacion; CotizacionFuncion[i].FechaCreacion = System.DateTime.Now; db.CotizacionFuncion.Add(CotizacionFuncion[i]); } else { cotizaciones = cotizaciones.Where(w => w.NombreFuncion != CotizacionFuncion[i].NombreFuncion).ToList(); } } db.SaveChanges(); foreach (CotizacionFuncion cot in cotizaciones) { db.CotizacionFuncion.Remove(cot); db.SaveChanges(); } } else { return(Json(new { Message = mensaje })); } return(Json(new { Message = clsReferencias.Exito })); } catch (Exception ex) { return(Json(new { Message = new clsException(ex).Message() })); } }