public async Task <Response> PostBrigadaSSO([FromBody] BrigadaSSO BrigadaSSO) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = "" }); } var respuesta = Existe(BrigadaSSO); if (!respuesta.IsSuccess) { db.BrigadaSSO.Add(BrigadaSSO); await db.SaveChangesAsync(); return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio, Resultado = BrigadaSSO, }); } 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, }); } }
// [Authorize(Policy = "EstaAutorizado")] public async Task <IActionResult> Create(BrigadaSSO brigadaSSO) { if (!ModelState.IsValid) { InicializarMensaje(null); return(View(brigadaSSO)); } Response response = new Response(); try { response = await apiServicio.InsertarAsync(brigadaSSO, new Uri(WebApp.BaseAddress), "api/BrigadasSSO/InsertarBrigadaSSO"); if (response.IsSuccess) { var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), ExceptionTrace = null, Message = "Se ha creado una Brigada Salud y Seguridad Ocupacional", UserName = "******", LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), EntityID = string.Format("{0} {1}", "Brigada Salud y Seguridad Ocupacional:", brigadaSSO.IdBrigadaSSO), }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(brigadaSSO)); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Creando Brigada de Salud y Seguridad Ocupacional", ExceptionTrace = ex.Message, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
public async Task <IActionResult> Edit(string id, BrigadaSSO brigadaSSO) { Response response = new Response(); try { if (!string.IsNullOrEmpty(id)) { response = await apiServicio.EditarAsync(id, brigadaSSO, new Uri(WebApp.BaseAddress), "/api/BrigadasSSO"); if (response.IsSuccess) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), EntityID = string.Format("{0} : {1}", "Brigada Salud y Seguridad Ocupacional", id), LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), Message = "Se ha actualizado una Brigada Salud y Seguridad Ocupacional", UserName = "******" }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(brigadaSSO)); } return(BadRequest()); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Editando una Brigada Salud y Seguridad Ocupacional", ExceptionTrace = ex, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
private Response Existe(BrigadaSSO BrigadaSSO) { var bdd = BrigadaSSO.Nombre.ToUpper().TrimEnd().TrimStart(); var BrigadaSSOrespuesta = db.BrigadaSSO.Where(p => p.Nombre.ToUpper().TrimStart().TrimEnd() == bdd).FirstOrDefault(); if (BrigadaSSOrespuesta != null) { return(new Response { IsSuccess = true, Message = Mensaje.ExisteRegistro, Resultado = null, }); } return(new Response { IsSuccess = false, Resultado = BrigadaSSOrespuesta, }); }
public async Task <List <BrigadaSSORol> > ListarBrigadasSSORolesPorBrigadaSSO([FromBody] BrigadaSSO brigadaSSO) { try { var lista = await db.BrigadaSsorol .Where(x => x.IdBrigadaSSO == brigadaSSO.IdBrigadaSSO) .OrderBy(x => x.Nombre).ToListAsync(); return(lista); } catch (Exception ex) { return(new List <BrigadaSSORol>()); } }
public async Task <Response> PutBrigadaSSO([FromRoute] int id, [FromBody] BrigadaSSO BrigadaSSO) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var existe = Existe(BrigadaSSO); if (existe.IsSuccess) { return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var BrigadaSSOActualizar = await db.BrigadaSSO.Where(x => x.IdBrigadaSSO == id).FirstOrDefaultAsync(); if (BrigadaSSOActualizar != null) { try { BrigadaSSOActualizar.Nombre = BrigadaSSO.Nombre; db.BrigadaSSO.Update(BrigadaSSOActualizar); 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 = 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 }); } }