Example #1
0
        /// <summary>
        /// Crea un lineamiento
        /// </summary>
        /// <param name="Lineamientos">objeto con los datos para crear</param>
        public async Task Create(Lineamientos model)
        {
            try
            {
                var registro = _db.DbSetLineamientos.Add(model);
                await _db.SaveChangesAsync();

                NuevoOCRepository ocrepo = new NuevoOCRepository();
                //Los parametros son: moduloid, id del oc (en este caso son strings), descripcion, liga del detalle del oc
                NuevoOC nuevoOC = new NuevoOC("CP", "LineamientosCP", registro.Nombre, "indexCP.html#/consultaLineamientos/");
                await ocrepo.Create(nuevoOC);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Example #2
0
        public async Task <IHttpActionResult> CreateLineamiento([FromBody] Lineamientos model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                log.Info(new MDCSet(this.ControllerContext.RouteData));
                var lineamiento = await _entityRepo.ReturnCreatedLineamiento(model);

                return(Ok(lineamiento));
            }
            catch (Exception e)
            {
                log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                return(InternalServerError(e));
            }
        }
Example #3
0
        public async Task <IHttpActionResult> Create([FromBody] Lineamientos model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                log.Info(new MDCSet(this.ControllerContext.RouteData));
                await _entityRepo.Create(model);

                return(Ok("Registro creado exitosamente!"));
            }
            catch (Exception e)
            {
                log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                return(InternalServerError(e));
            }
        }
Example #4
0
        public async Task Update(Lineamientos model)
        {
            try
            {
                var _model = await _db.DbSetLineamientos.FirstOrDefaultAsync(e => e.LineamientoId == model.LineamientoId);

                if (_model != null)
                {
                    if (model.Adjunto != null)
                    {
                        if (_model.AdjuntoId != null)
                        {
                            var id = _model.AdjuntoId;
                            _model.AdjuntoId = null;
                            await _db.SaveChangesAsync();

                            await _adjuntoRepo.Delete(id);
                        }

                        Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto);

                        model.AdjuntoId = key.AdjuntoId;
                    }
                    else
                    {
                        model.AdjuntoId = null;
                    }
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }