public async Task <IActionResult> GetCustomerPartnersById(Int64 PartnerId) { CustomerPartners Items = new CustomerPartners(); try { Items = await _context.CustomerPartners.Where(q => q.PartnerId == PartnerId).FirstOrDefaultAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(Items))); }
public async Task <ActionResult <CustomerPartners> > Insert([FromBody] CustomerPartners _CustomerPartners) { CustomerPartners _CustomerPartnersq = new CustomerPartners(); try { _CustomerPartnersq = _CustomerPartners; _context.CustomerPartners.Add(_CustomerPartnersq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_CustomerPartnersq))); }
public async Task <IActionResult> Delete([FromBody] CustomerPartners _CustomerPartners) { CustomerPartners _CustomerPartnersq = new CustomerPartners(); try { _CustomerPartnersq = _context.CustomerPartners .Where(x => x.PartnerId == (Int64)_CustomerPartners.PartnerId) .FirstOrDefault(); _context.CustomerPartners.Remove(_CustomerPartnersq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(_CustomerPartnersq))); }
public async Task <ActionResult <CustomerPartners> > Update([FromBody] CustomerPartners _CustomerPartners) { CustomerPartners _CustomerPartnersq = _CustomerPartners; try { _CustomerPartnersq = await(from c in _context.CustomerPartners .Where(q => q.PartnerId == _CustomerPartners.PartnerId) select c ).FirstOrDefaultAsync(); _context.Entry(_CustomerPartnersq).CurrentValues.SetValues((_CustomerPartners)); //_context.CustomerPartners.Update(_CustomerPartnersq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(_CustomerPartnersq))); }