public async Task <Response> PostFormularioCapacitacion([FromBody] FormularioCapacitacion FormularioCapacitacion) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var respuesta = Existe(FormularioCapacitacion); if (!respuesta.IsSuccess) { db.FormularioCapacitacion.Add(FormularioCapacitacion); 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(FormularioCapacitacion FormularioCapacitacion) { if (!ModelState.IsValid) { InicializarMensaje(null); return(View(FormularioCapacitacion)); } Response response = new Response(); try { response = await apiServicio.InsertarAsync(FormularioCapacitacion, new Uri(WebApp.BaseAddress), "api/FormularioCapacitaciones/InsertarFormularioCapacitacion"); if (response.IsSuccess) { var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), ExceptionTrace = null, Message = "Se ha creado un formulario capacitación", UserName = "******", LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), EntityID = string.Format("{0} {1}", "Form. Capacitación:", FormularioCapacitacion.IdFormularioCapacitacion), }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(FormularioCapacitacion)); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Creando formulario capacitación", ExceptionTrace = ex.Message, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
public async Task <IActionResult> Edit(string id, FormularioCapacitacion FormularioCapacitacion) { Response response = new Response(); try { if (!string.IsNullOrEmpty(id)) { response = await apiServicio.EditarAsync(id, FormularioCapacitacion, new Uri(WebApp.BaseAddress), "/api/FormularioCapacitaciones"); 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(FormularioCapacitacion)); } return(BadRequest()); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Editando un formulario capacitación", ExceptionTrace = ex, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
private Response Existe(FormularioCapacitacion FormularioCapacitacion) { string bdd = FormularioCapacitacion.Descripcion; var FormularioCapacitacionrespuesta = db.FormularioCapacitacion.Where(p => p.Descripcion.ToUpper() == FormularioCapacitacion.Descripcion.ToUpper()).FirstOrDefault(); if (FormularioCapacitacionrespuesta != null) { return(new Response { IsSuccess = true, Message = Mensaje.ExisteRegistro, Resultado = null, }); } return(new Response { IsSuccess = false, Resultado = FormularioCapacitacionrespuesta, }); }
public async Task <Response> PutFormularioCapacitacion([FromRoute] int id, [FromBody] FormularioCapacitacion FormularioCapacitacion) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var existe = Existe(FormularioCapacitacion); if (existe.IsSuccess) { return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var FormularioCapacitacionActualizar = await db.FormularioCapacitacion.Where(x => x.IdFormularioCapacitacion == id).FirstOrDefaultAsync(); if (FormularioCapacitacionActualizar != null) { try { FormularioCapacitacionActualizar.Descripcion = FormularioCapacitacion.Descripcion; 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 }); } }