public async Task <Response> PostInstruccionFormal([FromBody] InstruccionFormal InstruccionFormal) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var respuesta = Existe(InstruccionFormal); if (!respuesta.IsSuccess) { db.InstruccionFormal.Add(InstruccionFormal); await db.SaveChangesAsync(); return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio }); } return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro }); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.SwTH), ExceptionTrace = ex.Message, Message = Mensaje.Excepcion, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "", }); return(new Response { IsSuccess = false, Message = Mensaje.Error, }); } }
public async Task <IActionResult> Create(InstruccionFormal InstruccionFormal) { if (!ModelState.IsValid) { InicializarMensaje(null); return(View(InstruccionFormal)); } Response response = new Response(); try { response = await apiServicio.InsertarAsync(InstruccionFormal, new Uri(WebApp.BaseAddress), "api/InstruccionesFormales/InsertarInstruccionesFormales"); if (response.IsSuccess) { var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), ExceptionTrace = null, Message = "Se ha creado un Instruccion Formal", UserName = "******", LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), EntityID = string.Format("{0} {1}", "InstruccionFormal:", InstruccionFormal.IdInstruccionFormal), }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(InstruccionFormal)); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Creando InstruccionFormal", ExceptionTrace = ex.Message, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
public async Task <IActionResult> Edit(string id, InstruccionFormal InstruccionFormal) { Response response = new Response(); try { if (!string.IsNullOrEmpty(id)) { response = await apiServicio.EditarAsync(id, InstruccionFormal, new Uri(WebApp.BaseAddress), "/api/InstruccionesFormales"); if (response.IsSuccess) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), EntityID = string.Format("{0} : {1}", "Sistema", id), LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), Message = "Se ha actualizado un registro sistema", UserName = "******" }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(InstruccionFormal)); } return(BadRequest()); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Editando un Instruccion Formal", ExceptionTrace = ex, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
private Response Existe(InstruccionFormal InstruccionFormal) { var bdd = InstruccionFormal.Nombre; var InstruccionFormalrespuesta = db.InstruccionFormal.Where(p => p.Nombre == bdd).FirstOrDefault(); if (InstruccionFormalrespuesta != null) { return(new Response { IsSuccess = true, Message = Mensaje.ExisteRegistro, Resultado = null, }); } return(new Response { IsSuccess = false, Resultado = InstruccionFormalrespuesta, }); }
public async Task <Response> PutInstruccionFormal([FromRoute] int id, [FromBody] InstruccionFormal InstruccionFormal) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var existe = Existe(InstruccionFormal); if (existe.IsSuccess) { return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var InstruccionFormalActualizar = await db.InstruccionFormal.Where(x => x.IdInstruccionFormal == id).FirstOrDefaultAsync(); if (InstruccionFormalActualizar != null) { try { InstruccionFormalActualizar.Nombre = InstruccionFormal.Nombre; await db.SaveChangesAsync(); return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio, }); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.SwTH), ExceptionTrace = ex.Message, Message = Mensaje.Excepcion, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "", }); return(new Response { IsSuccess = false, Message = Mensaje.Error, }); } } return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro }); } catch (Exception) { return(new Response { IsSuccess = false, Message = Mensaje.Excepcion }); } }