예제 #1
0
        public async Task UpdateStadoOrCreate(LikesLinked model)
        {
            try
            {
                var _model = await _db.bdSetLikesLinked.FirstOrDefaultAsync(
                    e => e.Aprobador.Equals(model.Aprobador) && e.Empleado.Equals(model.Empleado) &&
                    e.IdExteno.Equals(model.IdExteno) && e.Tipo == 1);

                if (_model != null)
                {
                    model.Id = _model.Id;

                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
                else
                {
                    await this.Create(model);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
예제 #2
0
 private async Task Create(LikesLinked model)
 {
     try
     {
         _db.bdSetLikesLinked.Add(model);
         await _db.SaveChangesAsync();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message, e);
     }
 }
예제 #3
0
        public async Task Update(LikesLinked model)
        {
            try
            {
                var _model = await _db.bdSetLikesLinked.FirstOrDefaultAsync(e => e.Id == model.Id);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
예제 #4
0
        public async Task <IHttpActionResult> Update([FromBody] LikesLinked model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await _entityRepo.Update(model);

                return(Ok("Registro actualizado exitosamente!"));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }