public async Task <EmergencyDirectory> UpdateAsync(EmergencyDirectory emergencyDirectory) { this.context.emergencyDirectories.Update(emergencyDirectory); await SaveAllAsync(emergencyDirectory); return(emergencyDirectory); }
public async Task <EmergencyDirectory> CreateAsync(EmergencyDirectory emergencyDirectory) { await this.context.emergencyDirectories.AddAsync(emergencyDirectory); await SaveAllAsync(emergencyDirectory); return(emergencyDirectory); }
public async Task <IActionResult> PutEmergencyDirectory(int id, EmergencyDirectory emergencyDirectory) { if (id != emergencyDirectory.EmergencyDirectoryId) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = "El ID no corresponde a ningĂșn contacoto de emergencias" })); } if (ModelState.IsValid) { try { await _emergencyDirectoryDAO.UpdateAsync(emergencyDirectory); return(Ok(new Response { Status = "OK", Message = "Se actualizo correctamente" })); } catch (DbUpdateConcurrencyException ex) { if (!await _emergencyDirectoryDAO.ExistNameAsync(emergencyDirectory.NameArea)) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = "El ID no corresponde a ningĂșn contacoto de emergencias" })); } else { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = "Error inesperado consulte al administrador " + ex.Message })); } } } return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = "Favor de verificar los campos" })); }
public async Task <bool> SaveAllAsync(EmergencyDirectory emergencyDirectory) { try { return(await this.context.SaveChangesAsync() > 0); } catch (Exception ex) { SystemLog systemLog = new SystemLog(); systemLog.Description = ex.ToMessageAndCompleteStacktrace(); systemLog.DateLog = DateTime.UtcNow.ToLocalTime(); systemLog.Controller = GetType().Name; systemLog.Action = UtilitiesAIO.GetCallerMemberName(); systemLog.Parameter = JsonConvert.SerializeObject(emergencyDirectory); _customSystemLog.AddLog(systemLog); return(false); } }
public async Task <ActionResult <EmergencyDirectory> > PostEmergencyDirectory(EmergencyDirectory emergencyDirectory) { if (ModelState.IsValid) { if (!await _emergencyDirectoryDAO.ExistNameAsync(emergencyDirectory.NameArea)) { try { await this._emergencyDirectoryDAO.CreateAsync(emergencyDirectory); //var resp = await this._emergencyDirectoryDAO.CreateAsync(emergencyDirectory); //return Ok(new Response { Status = "OK", Message = "Se ha guardado correctamente", entidad = resp }); return(Ok(new Response { Status = "OK", Message = "Se ha guardado correctamente" })); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = "Error inesperado consulte al administrador del sistema " + ex.Message })); } } } return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = "Favor de verificar sus campos" })); }
public async Task DeleteAsync(EmergencyDirectory emergencyDirectory) { this.context.emergencyDirectories.Remove(emergencyDirectory); await SaveAllAsync(emergencyDirectory); }