public async Task <Response> PostCapacitacionModalidad([FromBody] CapacitacionModalidad CapacitacionModalidad) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = "", }); } var respuesta = Existe(CapacitacionModalidad); if (!respuesta.IsSuccess) { db.CapacitacionModalidad.Add(CapacitacionModalidad); 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(CapacitacionModalidad capacitacionModalidad) { if (!ModelState.IsValid) { InicializarMensaje(null); return(View(capacitacionModalidad)); } Response response = new Response(); try { response = await apiServicio.InsertarAsync(capacitacionModalidad, new Uri(WebApp.BaseAddress), "api/CapacitacionesModalidades/InsertarCapacitacionModalidad"); if (response.IsSuccess) { var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), ExceptionTrace = null, Message = "Se ha creado una modalidad de capacitación", UserName = "******", LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), EntityID = string.Format("{0} {1}", "Modalidad de Capacitación:", capacitacionModalidad.IdCapacitacionModalidad), }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(capacitacionModalidad)); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Creando Modalidad de 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, CapacitacionModalidad capacitacionModalidad) { Response response = new Response(); try { if (!string.IsNullOrEmpty(id)) { response = await apiServicio.EditarAsync(id, capacitacionModalidad, new Uri(WebApp.BaseAddress), "/api/CapacitacionesModalidades"); if (response.IsSuccess) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), EntityID = string.Format("{0} : {1}", "Modalidad de Capacitación", id), LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), Message = "Se ha actualizado una modalidad de capacitación", UserName = "******" }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(capacitacionModalidad)); } return(BadRequest()); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Editando una modalidad de capacitación", ExceptionTrace = ex, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
private Response Existe(CapacitacionModalidad CapacitacionModalidad) { var bdd = CapacitacionModalidad.Descripcion.ToUpper().TrimEnd().TrimStart(); var CapacitacionModalidadrespuesta = db.CapacitacionModalidad.Where(p => p.Descripcion.ToUpper().TrimStart().TrimEnd() == bdd).FirstOrDefault(); if (CapacitacionModalidadrespuesta != null) { return(new Response { IsSuccess = true, Message = Mensaje.ExisteRegistro, Resultado = null, }); } return(new Response { IsSuccess = false, Resultado = CapacitacionModalidadrespuesta, }); }
public async Task <Response> PutCapacitacionModalidad([FromRoute] int id, [FromBody] CapacitacionModalidad CapacitacionModalidad) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido, }); } var existe = Existe(CapacitacionModalidad); if (existe.IsSuccess) { return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var CapacitacionModalidadActualizar = await db.CapacitacionModalidad.Where(x => x.IdCapacitacionModalidad == id).FirstOrDefaultAsync(); if (CapacitacionModalidadActualizar != null) { try { CapacitacionModalidadActualizar.Descripcion = CapacitacionModalidad.Descripcion; db.CapacitacionModalidad.Update(CapacitacionModalidadActualizar); 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, }); } }