public static Data.bt_ord_trabajo ConvertToBD(otModel orden) { Data.bt_ord_trabajo ot = new Data.bt_ord_trabajo(); ot.ot_id = orden.ot_id; ot.cliente_sk = orden.cliente_sk; ot.tecnico_sk = orden.tecnico_sk; ot.calificacion = orden.calificacion; ot.descripcion = orden.descripcion; ot.tipo = orden.tipo_id; if (orden.fh_creacion != null) { ot.fh_creacion = DateTime.ParseExact(orden.fh_creacion, "dd-MM-yyyy", null); } else { ot.fh_creacion = DateTime.Today; } if (orden.fh_cierre != null) { ot.fh_cierre = DateTime.ParseExact(orden.fh_cierre, "dd-MM-yyyy", null); } else { ot.fh_cierre = DateTime.ParseExact("31-12-2999", "dd-MM-yyyy", null); }; return(ot); }
public static otModel ConvertTo(Data.bt_ord_trabajo n, Data.lk_tipo_ot[] tipos) { otModel ot = new otModel(); DateTime fh_cierre_d; if (n.fh_cierre != null) { fh_cierre_d = (DateTime)n.fh_cierre; } else { fh_cierre_d = DateTime.MaxValue; } ot.ot_id = n.ot_id; ot.cliente_sk = n.cliente_sk; ot.tecnico_sk = n.tecnico_sk; ot.fh_creacion = n.fh_creacion.ToString("dd-MM-yyyy"); ot.fh_cierre = fh_cierre_d.ToString("dd-MM-yyyy"); if (n.calificacion == null) { ot.calificacion = 0; } else { ot.calificacion = (decimal)n.calificacion; } ot.descripcion = n.descripcion; ot.tipo_id = n.tipo; ot.tipo = tipos[n.tipo - 1].tipo_ot_desc; return(ot); }
public IHttpActionResult Postbt_ot_status(Models.ot_statusModel estado) { string notificacion_desc = ""; string notificacion_texto = ""; bt_ot_status bt_ot_status = Models.ot_statusModel.ConvertToBD(estado); db.bt_ot_status.Add(bt_ot_status); db.SaveChanges(); estado.tiempo_sk = bt_ot_status.tiempo_sk.ToString("yyyy-MM-dd"); estado.hh_mm_ss = bt_ot_status.hh_mm_ss; estado.timestamp = string.Concat(bt_ot_status.tiempo_sk.ToString("yyyy-MM-dd"), " ", bt_ot_status.hh_mm_ss); if (estado.estado_sk == 3 || estado.estado_sk == 2) { // actualizo el estado de cierre de la OT Data.bt_ord_trabajo ot = db.bt_ord_trabajo.Where(x => x.ot_id == estado.ot_id).FirstOrDefault(); if (estado.estado_sk == 3) { //FINALIZADA ot.fh_cierre = DateTime.Today; db.SaveChanges(); notificacion_desc = string.Concat("Orden ", estado.ot_id.ToString(), " resuelta"); notificacion_texto = string.Concat("La orden ", estado.ot_id.ToString(), " ha sido resuelta, ante cualquier consulta no dude en informarnos"); } else { // EN CURSO tecnico t = null; int tecnico_sk; if (ot.tecnico_sk != null) { tecnico_sk = (int)ot.tecnico_sk; t = (from tec in db.tecnicos where tec.tecnico_sk == tecnico_sk select tec).FirstOrDefault(); } notificacion_desc = string.Concat("Orden ", estado.ot_id.ToString(), " en curso"); if (t != null) { notificacion_texto = "Técnico asignado: " + t.tecnico_desc;// string.Concat("El reclamo ", estado.ot_id.ToString(), " esta en curso"); } } // Doy de alta la notificacion en la LK Data.lk_notificacion noti = new Data.lk_notificacion(); noti.notificacion_desc = notificacion_desc; noti.notificacion_texto = notificacion_texto; noti.notificacion_tipo = "OT y OS"; db.lk_notificacion.Add(noti); db.SaveChanges(); // Busco los usuarios del cliente de la OT List <usuario> usuarios = _clienteService.findUsersByClient(ot.cliente_sk); // Armo una notificacion por cada Usuario foreach (usuario u in usuarios) { Data.bt_notificaciones bt_not = new Data.bt_notificaciones(); bt_not.usuario_sk = u.usuario_sk; bt_not.cliente_sk = u.cliente_sk; bt_not.notificacion_sk = noti.notificacion_sk; bt_not.tiempo_sk = DateTime.Today; bt_not.ot_id = estado.ot_id; db.bt_notificaciones.Add(bt_not); } db.SaveChanges(); // Mando Notificacion Push Service.FirebaseService.notificacion_mensaje m = new Service.FirebaseService.notificacion_mensaje(); m.cliente_sk = ot.cliente_sk; m.usuario_sk = 0; m.titulo = noti.notificacion_desc; fb.EnviarAFCM(m); } return(CreatedAtRoute("DefaultApi", new { id = estado.ot_id }, estado)); }