public async Task <Response> PostAnoExperiencia([FromBody] AnoExperiencia AnoExperiencia) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = "" }); } var respuesta = Existe(AnoExperiencia); if (!respuesta.IsSuccess) { db.AnoExperiencia.Add(AnoExperiencia); 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 = 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> Edit(string id, AnoExperiencia anoExperiencia) { Response response = new Response(); try { if (!string.IsNullOrEmpty(id)) { response = await apiServicio.EditarAsync(id, anoExperiencia, new Uri(WebApp.BaseAddress), "/api/AnosExperiencia"); if (response.IsSuccess) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), EntityID = string.Format("{0} : {1}", "Año Experiencia", id), LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), Message = "Se ha actualizado un año experiencia", UserName = "******" }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(anoExperiencia)); } return(BadRequest()); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Editando un año experiencia", ExceptionTrace = ex, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
public async Task <IActionResult> Create(AnoExperiencia anoExperiencia) { Response response = new Response(); try { response = await apiServicio.InsertarAsync(anoExperiencia, new Uri(WebApp.BaseAddress), "/api/AnosExperiencia/InsertarAnoExperiencia"); if (response.IsSuccess) { var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), ExceptionTrace = null, Message = "Se ha creado un año experiencia", UserName = "******", LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), EntityID = string.Format("{0} {1}", "Año Experiencia:", anoExperiencia.IdAnoExperiencia), }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; return(View(anoExperiencia)); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Creando Año Experiencia", ExceptionTrace = ex, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
private Response Existe(AnoExperiencia AnoExperiencia) { var bdd = AnoExperiencia.Descripcion.ToUpper().TrimEnd().TrimStart(); var AnoExperienciarespuesta = db.AnoExperiencia.Where(p => p.Descripcion.ToUpper().TrimStart().TrimEnd() == bdd).FirstOrDefault(); if (AnoExperienciarespuesta != null) { return(new Response { IsSuccess = true, Message = Mensaje.ExisteRegistro, Resultado = null, }); } return(new Response { IsSuccess = false, Resultado = AnoExperienciarespuesta, }); }
public async Task <Response> PutAnoExperiencia([FromRoute] int id, [FromBody] AnoExperiencia AnoExperiencia) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var existe = Existe(AnoExperiencia); if (existe.IsSuccess) { return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var AnoExperienciaActualizar = await db.AnoExperiencia.Where(x => x.IdAnoExperiencia == id).FirstOrDefaultAsync(); if (AnoExperienciaActualizar != null) { try { AnoExperienciaActualizar.Descripcion = AnoExperiencia.Descripcion; db.AnoExperiencia.Update(AnoExperienciaActualizar); 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 }); } }