Beispiel #1
0
 public async Task Create(CursosPersonal model)
 {
     try
     {
         _db.dbSetCursosPersonal.Add(model);
         await _db.SaveChangesAsync();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message, e);
     }
 }
Beispiel #2
0
        public async Task UpdateEstado(CursosPersonal model)
        {
            try
            {
                var _model = await _db.dbSetCursosPersonal.FirstOrDefaultAsync(e => e.CursosPersonalId == model.CursosPersonalId);

                if (_model != null)
                {
                    _model.EstadoActivoId = model.EstadoActivoId;
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Beispiel #3
0
        public async Task Update(CursosPersonal model)
        {
            try
            {
                var _model = await _db.dbSetCursosPersonal
                             .FirstOrDefaultAsync(e => e.CursosPersonalId == model.CursosPersonalId);

                if (_model != null)
                {
                    foreach (var adjuntoCursosPersonal in model.AdjuntoCursosPersonal)
                    {
                        if (adjuntoCursosPersonal.Adjunto != null)
                        {
                            try
                            {
                                if (adjuntoCursosPersonal.Adjunto.AdjuntoId < 1) //NUEVO ADJUNTO
                                {
                                    _dbGen.dbSetAdjuntos.Add(adjuntoCursosPersonal.Adjunto);
                                    await _dbGen.SaveChangesAsync(); //guardar el adjunto

                                    adjuntoCursosPersonal.AdjuntoId        = adjuntoCursosPersonal.Adjunto.AdjuntoId;
                                    adjuntoCursosPersonal.CursosPersonalId = model.CursosPersonalId;
                                    //guardar nuevo adjuntoCursosPersonal
                                    _db.dbSetAdjuntoCursosPersonal.Add(adjuntoCursosPersonal);
                                    await _db.SaveChangesAsync(); //guardar el adjunto
                                }
                                else //adjunto existente: actualizar el adjunto
                                {
                                    var _modelAdjunto = await _dbGen.dbSetAdjuntos.FirstOrDefaultAsync(e => e.AdjuntoId == adjuntoCursosPersonal.Adjunto.AdjuntoId);

                                    _dbGen.Entry(_modelAdjunto).CurrentValues.SetValues(adjuntoCursosPersonal.Adjunto);
                                    await _dbGen.SaveChangesAsync();
                                }
                            }
                            catch (Exception e)
                            {
                                throw new Exception(e.Message, e);
                            }
                        }
                    }
                    foreach (var autoresCursosPersonal in model.AutoresCursosPersonal)
                    {
                        try
                        {
                            if (autoresCursosPersonal.AutoresCursosPersonalId < 1)     //NUEVO Autor
                            {
                                autoresCursosPersonal.Autor_ClavePersona      = autoresCursosPersonal.Autor_ClavePersona;
                                autoresCursosPersonal.Autor_Nombre            = autoresCursosPersonal.Autor_Nombre;
                                autoresCursosPersonal.CursosPersonalId        = model.CursosPersonalId;
                                autoresCursosPersonal.AutoresCursosPersonalId = autoresCursosPersonal.AutoresCursosPersonalId;
                                //guardar nuevo adjuntoCursosPersonal
                                _db.dbSetAutoresCursosPersonal.Add(autoresCursosPersonal);
                                await _db.SaveChangesAsync(); //guardar el adjunto
                            }
                            else                              //adjunto existente: actualizar el adjunto
                            {
                                var _modelAutores = await _db.dbSetAutoresCursosPersonal.FirstOrDefaultAsync(e => e.AutoresCursosPersonalId == autoresCursosPersonal.AutoresCursosPersonalId);

                                _db.Entry(_modelAutores).CurrentValues.SetValues(autoresCursosPersonal);
                                await _db.SaveChangesAsync();
                            }
                        }
                        catch (Exception e)
                        {
                            throw new Exception(e.Message, e);
                        }
                    }
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
                                                            public async Task <IHttpActionResult> UpdateEstado([FromBody] CursosPersonal CursosPersonal)
                                                            {
                                                                try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                      await _CursosPersonalRepo.UpdateEstado(CursosPersonal);

                                                                      return(Ok("Registro actualizado correctamente")); }
                                                                catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e);

                                                                                      return(InternalServerError(e)); }
                                                            }