public async Task <Response> PostModalidadPartida([FromBody] ModalidadPartida ModalidadPartida) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = "" }); } var respuesta = Existe(ModalidadPartida); if (!respuesta.IsSuccess) { db.ModalidadPartida.Add(ModalidadPartida); 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> Create(ModalidadPartida ModalidadPartida) { if (!ModelState.IsValid) { InicializarMensaje(null); return(View(ModalidadPartida)); } Response response = new Response(); try { response = await apiServicio.InsertarAsync(ModalidadPartida, new Uri(WebApp.BaseAddress), "api/ModalidadesPartida/InsertarModalidadPartida"); if (response.IsSuccess) { var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), ExceptionTrace = null, Message = "Se ha creado una modalidad partida", UserName = "******", LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), EntityID = string.Format("{0} {1}", "Modalidad Partida:", ModalidadPartida.IdModalidadPartida), }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; ViewData["IdRelacionLaboral"] = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await apiServicio.Listar <RelacionLaboral>(new Uri(WebApp.BaseAddress), "api/RelacionesLaborales/ListarRelacionesLaborales"), "IdRelacionLaboral", "Nombre"); return(View(ModalidadPartida)); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Creando modalidad partida", ExceptionTrace = ex.Message, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
public async Task <IActionResult> Edit(string id, ModalidadPartida ModalidadPartida) { Response response = new Response(); try { if (!string.IsNullOrEmpty(id)) { response = await apiServicio.EditarAsync(id, ModalidadPartida, new Uri(WebApp.BaseAddress), "/api/ModalidadesPartida"); if (response.IsSuccess) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), EntityID = string.Format("{0} : {1}", "Modalidad Partida", id), LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), Message = "Se ha actualizado una modalidad partida", UserName = "******" }); return(RedirectToAction("Index")); } ViewData["Error"] = response.Message; ViewData["IdRelacionLaboral"] = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await apiServicio.Listar <RelacionLaboral>(new Uri(WebApp.BaseAddress), "api/RelacionesLaborales/ListarRelacionesLaborales"), "IdRelacionLaboral", "Nombre"); return(View(ModalidadPartida)); } return(BadRequest()); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppTh), Message = "Editando una modalidad partida", ExceptionTrace = ex, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" }); return(BadRequest()); } }
private Response Existe(ModalidadPartida ModalidadPartida) { var bdd = ModalidadPartida.Nombre.ToUpper().TrimEnd().TrimStart(); var ModalidadPartidarespuesta = db.ModalidadPartida.Where(p => p.Nombre.ToUpper().TrimStart().TrimEnd() == bdd && p.IdRelacionLaboral == ModalidadPartida.IdRelacionLaboral).FirstOrDefault(); if (ModalidadPartidarespuesta != null) { return(new Response { IsSuccess = true, Message = Mensaje.ExisteRegistro, Resultado = ModalidadPartidarespuesta, }); } return(new Response { IsSuccess = false, Resultado = ModalidadPartidarespuesta, }); }
public async Task <Response> PutModalidadPartida([FromRoute] int id, [FromBody] ModalidadPartida ModalidadPartida) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var existe = Existe(ModalidadPartida); var ModalidadPartidaActualizar = (ModalidadPartida)existe.Resultado; if (existe.IsSuccess) { if (ModalidadPartidaActualizar.IdModalidadPartida == ModalidadPartida.IdModalidadPartida) { return(new Response { IsSuccess = true, }); } return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var modalidadpartida = db.ModalidadPartida.Find(ModalidadPartida.IdModalidadPartida); modalidadpartida.IdRelacionLaboral = ModalidadPartida.IdRelacionLaboral; modalidadpartida.Nombre = ModalidadPartida.Nombre; db.ModalidadPartida.Update(modalidadpartida); 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 = true, Message = Mensaje.Excepcion, }); } }