internal IdentityError DeleteCurso(int cursoID) { IdentityError identityError; try { var curso = new TCursos { CursoID = cursoID }; context.Remove(curso); context.SaveChanges(); identityError = new IdentityError { Description = "Done" }; } catch (Exception e) { identityError = new IdentityError { Code = "Error", Description = e.Message }; } return(identityError); }
public async Task <IdentityError> RegistrarCursoAsync(DataPaginador <TCursos> model) { IdentityError identityError; try { var imageByte = await _image.ByteAvatarImageAsync(model.AvatarImage, environment); var curso = new TCursos { Nombre = model.Input.Nombre, Descripcion = model.Input.Descripcion, Horas = model.Input.Horas, Costo = model.Input.Costo, Estado = model.Input.Estado, Image = imageByte, CategoriaID = model.Input.CategoriaID }; context.Add(curso); context.SaveChanges(); identityError = new IdentityError { Code = "Done" }; } catch (Exception e) { identityError = new IdentityError { Code = "Error", Description = e.Message }; } return(identityError); }
// Metodo que retorna una tarea // la palabra "async" significa que este metodo se va a sincronizar con otro metodo que va a realizar // una tarea indicando que este metodo tiene q esperar y sincronizarce hasta que ese metodo termine // la tarea este metodo va a proseguir ejecutanto su procedimiento public async Task <IdentityError> RegistrarCursoAsync(DataPaginador <TCursos> model) { IdentityError identityError; try { if (model.Input.CursoID.Equals(0)) { // MODO DE RESGISTRAR UN CURSO // await le indica que este metodo tiene que ser esperado por var imageByte = await _image.ByteAvatarImageAsync(model.AvatarImage, environment); var curso = new TCursos { Curso = model.Input.Curso, Informacion = model.Input.Informacion, Horas = model.Input.Horas, Costo = model.Input.Costo, Estado = model.Input.Estado, Image = imageByte, CategoriaID = model.Input.CategoriaID }; // agrega un curso a la tabla TCurso de la BD. context.Add(curso); context.SaveChanges(); } else { // MODO DE ACTUALIZAR UN CURSO byte[] imageByte; if (model.AvatarImage != null) { // contriene una imagen que hemos cargado // y se actualiza la imagen del curso imageByte = await _image.ByteAvatarImageAsync(model.AvatarImage, environment); } else { // no se actuliza la imagen del curso // y le propocionamos la misma imagen imageByte = model.Input.Image; } var curso = new TCursos { CursoID = model.Input.CursoID, Curso = model.Input.Curso, Informacion = model.Input.Informacion, Horas = model.Input.Horas, Costo = model.Input.Costo, Estado = model.Input.Estado, Image = imageByte, CategoriaID = model.Input.CategoriaID }; // Actualiza el curso en la BD context.Update(curso); context.SaveChanges(); } identityError = new IdentityError { Code = "Done" }; } catch (Exception e) { identityError = new IdentityError { Code = "Error", Description = e.Message }; } return(identityError); }
public async Task <IdentityError> RegistrarCursoAsync(DataPaginador <TCursos> model) { IdentityError identityError; try { if (model.Input.CursoID.Equals(0)) //vamos agregar un curso { var imageByte = await _image.ByteAvatarImageAsync(model.AvatarImage, environment); var curso = new TCursos { Curso = model.Input.Curso, Informacion = model.Input.Informacion, Horas = model.Input.Horas, Costo = model.Input.Costo, Estado = model.Input.Estado, Image = imageByte, CategoriaID = model.Input.CategoriaID }; context.Add(curso); context.SaveChanges(); } else // vamos a actualizar un curso { byte[] imageByte; if (model.AvatarImage != null) // actualizar la imagen del curso si no es la dada por defecto { imageByte = await _image.ByteAvatarImageAsync(model.AvatarImage, environment); } else // Para no actualizar la imagen y dejar la misma { imageByte = model.Input.Image; } var curso = new TCursos { CursoID = model.Input.CursoID, Curso = model.Input.Curso, Informacion = model.Input.Informacion, Horas = model.Input.Horas, Costo = model.Input.Costo, Estado = model.Input.Estado, Image = imageByte, CategoriaID = model.Input.CategoriaID }; context.Update(curso); context.SaveChanges(); } identityError = new IdentityError { Code = "Done" }; } catch (Exception e) { identityError = new IdentityError { Code = "Error", Description = e.Message }; } return(identityError); }
public async Task <IdentityError> RegistrarCursoAsync(DataPaginador <TCursos> model) { IdentityError identityError; try { if (model.Input.CursosID.Equals(0)) { var imageByte = await _image.ByteAvatarImageAsync(model.AvatarImage, environment); var curso = new TCursos { Curso = model.Input.Curso, Informacion = model.Input.Informacion, Horas = model.Input.Horas, Costo = model.Input.Costo, Estado = model.Input.Estado, Image = imageByte, CategoriaID = model.Input.CategoriaID }; context.Add(curso); context.SaveChanges(); } else { byte[] imageByte; if (model.AvatarImage != null) { imageByte = await _image.ByteAvatarImageAsync(model.AvatarImage, environment); } else { imageByte = model.Input.Image; } var curso = new TCursos { CursosID = model.Input.CursosID, Curso = model.Input.Curso, Informacion = model.Input.Informacion, Horas = model.Input.Horas, Costo = model.Input.Costo, Estado = model.Input.Estado, Image = imageByte, CategoriaID = model.Input.CategoriaID }; context.Update(curso); context.SaveChanges(); } identityError = new IdentityError { Code = "Done" }; } catch (Exception e) { identityError = new IdentityError { Code = "Error", Description = e.Message }; } return(identityError); }