public CreacionLineaViewModel(BitacoraModel Model) { Orden = new BitacoraDetModel { Id = Model.Id, Linea = Model.Linea }; EsEmpleado = Model.EsEmpleado == 1 ? true : false; Contratista = Model.Contratista; Descripcion = Model.Descripcion; IsEnabled = true; apiService = new ApiService(); }
public void POST([FromBody] BitacoraDetModel model) { try { var Entity = db.DET_BITACORA.Where(q => q.ID == model.ID && q.LINEA == model.LINEA).FirstOrDefault(); if (Entity == null) { model.LINEA = (short)(db.DET_BITACORA.Where(q => q.ID == model.ID).Count() == 0 ? 1 : db.DET_BITACORA.Where(q => q.ID == model.ID).Max(q => q.LINEA) + 1); db.DET_BITACORA.Add(new DET_BITACORA { ID = model.ID, LINEA = model.LINEA, DESCRIPCION = model.DETALLEOT, CONTRATISTA = model.NOMPROVEEDOR, EMPRESA = 1, ST_EMPLEADO = model.ST_EMPLEADO }); } else { Entity.DESCRIPCION = model.DETALLEOT; Entity.CONTRATISTA = model.NOMPROVEEDOR; Entity.ST_EMPLEADO = model.ST_EMPLEADO; } db.SaveChanges(); } catch (Exception ex) { using (EntitiesGeneral Error = new EntitiesGeneral()) { long IDERROR = Error.APP_LOGERROR.Count() > 0 ? (Error.APP_LOGERROR.Select(q => q.SECUENCIA).Max() + 1) : 1; Error.APP_LOGERROR.Add(new APP_LOGERROR { ERROR = ex == null ? string.Empty : (ex.Message.Length > 1000 ? ex.Message.Substring(0, 1000) : ex.Message), INNER = ex.InnerException == null ? string.Empty : (ex.InnerException.Message.Length > 1000 ? ex.InnerException.Message.Substring(0, 1000) : ex.InnerException.Message), FECHA = DateTime.Now, PROCESO = "CreacionLinea/POST", SECUENCIA = IDERROR }); Error.SaveChanges(); } } }
public void Post([FromBody] BitacoraDetModel value) { try { if (!value.ELIMINAR) { short LINEA_DETALLE = 1; var lst = db.DET_BITACORA2.Where(q => q.ID == value.ID && q.LINEA == value.LINEA).Select(q => q.LINEA_DETALLE).ToList(); if (lst.Count > 0) { LINEA_DETALLE = (short)(lst.Max(q => q) + 1); } int NUMERO_ORDEN = 0; decimal VALOR_OT = 0; if (value.TIPO == "OT") { NUMERO_ORDEN = Convert.ToInt32(value.NUMERO_ORDEN); } var orden = db.VW_ORDENES_TRABAJO_TOTAL_APP.Where(q => q.CINV_TDOC == "OT" && q.CINV_NUM == NUMERO_ORDEN).FirstOrDefault(); if (orden != null) { NumberFormatInfo provider = new NumberFormatInfo(); provider.NumberDecimalSeparator = "."; provider.NumberGroupSeparator = ","; provider.NumberGroupSizes = new int[] { 3 }; VALOR_OT = (orden.CINV_TDOC == "OT") ? (Convert.ToDecimal(orden.CINV_COM3, provider) + Convert.ToDecimal(orden.CINV_COM4, provider)) : (orden.VALOR_OC == null ? 0 : Convert.ToDecimal(orden.VALOR_OC)); } db.DET_BITACORA2.Add(new DET_BITACORA2 { ID = value.ID, LINEA = value.LINEA, LINEA_DETALLE = LINEA_DETALLE, VALOR = VALOR_OT, NUMERO_ORDEN = value.NUMERO_ORDEN, EMPRESA = 1, CUMPLIMIENTO = 0, TIPO = value.TIPO }); } else { var obj = db.DET_BITACORA2.Where(q => q.ID == value.ID && q.LINEA == value.LINEA && q.NUMERO_ORDEN == value.NUMERO_ORDEN && q.TIPO == value.TIPO).FirstOrDefault(); if (obj != null) { db.DET_BITACORA2.Remove(obj); } } db.SaveChanges(); } catch (Exception ex) { long SECUENCIAID = db.APP_LOGERROR.Count() > 0 ? (db.APP_LOGERROR.Select(q => q.SECUENCIA).Max() + 1) : 1; db.APP_LOGERROR.Add(new APP_LOGERROR { ERROR = ex == null ? string.Empty : (ex.Message.Length > 1000 ? ex.Message.Substring(0, 1000) : ex.Message), INNER = ex.InnerException == null ? string.Empty : (ex.InnerException.Message.Length > 1000 ? ex.InnerException.Message.Substring(0, 1000) : ex.InnerException.Message), FECHA = DateTime.Now, PROCESO = "BitacorasDetJefeSup/POST", SECUENCIA = SECUENCIAID }); db.SaveChanges(); } }