public async Task <ActionResult <ProformaInvoiceLine> > Update(Int64 id, ProformaInvoiceLine _ProformaInvoiceLine) { try { string baseadress = config.Value.urlbase; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); var result = await _client.PutAsJsonAsync(baseadress + "api/ProformaInvoiceLine/Update", _ProformaInvoiceLine); string valorrespuesta = ""; if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _ProformaInvoiceLine = JsonConvert.DeserializeObject <ProformaInvoiceLine>(valorrespuesta); } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error{ex.Message}")); } return(new ObjectResult(new DataSourceResult { Data = new[] { _ProformaInvoiceLine }, Total = 1 })); }
public async Task <IActionResult> GetProformaInvoiceLineById(Int64 ProformaLineId) { ProformaInvoiceLine Items = new ProformaInvoiceLine(); try { Items = await _context.ProformaInvoiceLine.Where(q => q.ProformaLineId == ProformaLineId).FirstOrDefaultAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(Items))); }
//[HttpPost("[action]")] public ActionResult <ProformaInvoiceLine> Delete([FromBody] ProformaInvoiceLine _ProformaInvoiceLine) { try { List <ProformaInvoiceLine> _salesorderLIST = JsonConvert.DeserializeObject <List <ProformaInvoiceLine> >(HttpContext.Session.GetString("listadoproductosproformainvoice")); if (_salesorderLIST != null) { _salesorderLIST = _salesorderLIST .Where(q => q.ProformaLineId != _ProformaInvoiceLine.ProformaLineId) //.Where(q => q.Quantity != _ProformaInvoiceLine.Quantity) //.Where(q => q.Amount != _ProformaInvoiceLine.Amount) //.Where(q => q.Total != _ProformaInvoiceLine.Total) //.Where(q => q.Price != _ProformaInvoiceLine.Price) //.Where(q => q.SubProductId != _ProformaInvoiceLine.SubProductId) .ToList(); HttpContext.Session.SetString("listadoproductosproformainvoice", JsonConvert.SerializeObject(_salesorderLIST)); } //string baseadress = config.Value.urlbase; //HttpClient _client = new HttpClient(); //_client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); //var result = await _client.PostAsJsonAsync(baseadress + "api/ProformaInvoiceLine/Delete", _ProformaInvoiceLine); //string valorrespuesta = ""; //if (result.IsSuccessStatusCode) //{ // valorrespuesta = await (result.Content.ReadAsStringAsync()); // _ProformaInvoiceLine = JsonConvert.DeserializeObject<ProformaInvoiceLine>(valorrespuesta); //} } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error: {ex.Message}")); } return(new ObjectResult(new DataSourceResult { Data = new[] { _ProformaInvoiceLine }, Total = 1 })); }
public async Task <ActionResult <ProformaInvoiceLine> > Insert([FromBody] ProformaInvoiceLine _ProformaInvoiceLine) { ProformaInvoiceLine _ProformaInvoiceLineq = new ProformaInvoiceLine(); try { _ProformaInvoiceLineq = _ProformaInvoiceLine; _context.ProformaInvoiceLine.Add(_ProformaInvoiceLineq); 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(_ProformaInvoiceLineq))); }
public async Task <IActionResult> Delete([FromBody] ProformaInvoiceLine _ProformaInvoiceLine) { ProformaInvoiceLine _ProformaInvoiceLineq = new ProformaInvoiceLine(); try { _ProformaInvoiceLineq = _context.ProformaInvoiceLine .Where(x => x.ProformaLineId == (Int64)_ProformaInvoiceLine.ProformaLineId) .FirstOrDefault(); _context.ProformaInvoiceLine.Remove(_ProformaInvoiceLineq); 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(_ProformaInvoiceLineq))); }
public async Task <ActionResult <ProformaInvoiceLine> > SaveProformaInvoiceLine([FromBody] ProformaInvoiceLine _ProformaInvoiceLine) { try { ProformaInvoiceLine _listProformaInvoiceLine = new ProformaInvoiceLine(); string baseadress = config.Value.urlbase; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); var result = await _client.GetAsync(baseadress + "api/ProformaInvoiceLine/GetProformaInvoiceLineById/" + _ProformaInvoiceLine.ProformaLineId); string valorrespuesta = ""; // _ProformaInvoiceLine.FechaModificacion = DateTime.Now; //_ProformaInvoiceLine.UsuarioModificacion = HttpContext.Session.GetString("user"); if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _listProformaInvoiceLine = JsonConvert.DeserializeObject <ProformaInvoiceLine>(valorrespuesta); } if (_listProformaInvoiceLine.ProformaLineId == 0) { // _ProformaInvoiceLine.FechaCreacion = DateTime.Now; // _ProformaInvoiceLine.UsuarioCreacion = HttpContext.Session.GetString("user"); var insertresult = await Insert(_ProformaInvoiceLine); } else { var updateresult = await Update(_ProformaInvoiceLine.ProformaLineId, _ProformaInvoiceLine); } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } return(Json(_ProformaInvoiceLine)); }
public async Task <ActionResult <ProformaInvoiceLine> > Update([FromBody] ProformaInvoiceLine _ProformaInvoiceLine) { ProformaInvoiceLine _ProformaInvoiceLineq = _ProformaInvoiceLine; try { _ProformaInvoiceLineq = await(from c in _context.ProformaInvoiceLine .Where(q => q.ProformaLineId == _ProformaInvoiceLine.ProformaLineId) select c ).FirstOrDefaultAsync(); _context.Entry(_ProformaInvoiceLineq).CurrentValues.SetValues((_ProformaInvoiceLine)); //_context.ProformaInvoiceLine.Update(_ProformaInvoiceLineq); 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(_ProformaInvoiceLineq))); }
public async Task <DataSourceResult> GetProformaInvoiceLineByProformaInvoiceId([DataSourceRequest] DataSourceRequest request, ProformaInvoiceLine _ProformaInvoiceLinep) { List <ProformaInvoiceLine> _GoodsReceivedLine = new List <ProformaInvoiceLine>(); try { if (HttpContext.Session.Get("listadoproductosproformainvoice") == null || HttpContext.Session.GetString("listadoproductosproformainvoice") == "") { if (_ProformaInvoiceLinep.ProformaInvoiceId > 0) { string serialzado = JsonConvert.SerializeObject(_ProformaInvoiceLinep).ToString(); HttpContext.Session.SetString("listadoproductosproformainvoice", serialzado); } } else { var result = HttpContext.Session.GetString("listadoproductosproformainvoice"); try { _GoodsReceivedLine = JsonConvert.DeserializeObject <List <ProformaInvoiceLine> >(HttpContext.Session.GetString("listadoproductosproformainvoice")); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); } } if (_ProformaInvoiceLinep.ProformaInvoiceId > 0) { string baseadress = config.Value.urlbase; HttpClient _client = new HttpClient(); //_client.DefaultRequestHeaders.Add("SalesOrderId", _salesorder.SalesOrderId.ToString()); //_client.DefaultRequestHeaders.Add("SalesOrderId", _SalesOrderLine.SalesOrderId.ToString()); _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); var result = await _client.GetAsync(baseadress + "api/ProformaInvoiceLine/GetProformaInvoiceLineByProformaInvoiceId/" + _ProformaInvoiceLinep.ProformaInvoiceId); string valorrespuesta = ""; if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _GoodsReceivedLine = JsonConvert.DeserializeObject <List <ProformaInvoiceLine> >(valorrespuesta); HttpContext.Session.SetString("listadoproductosproformainvoice", JsonConvert.SerializeObject(_GoodsReceivedLine).ToString()); } } else { List <ProformaInvoiceLine> _existelinea = new List <ProformaInvoiceLine>(); if (HttpContext.Session.GetString("listadoproductosproformainvoice") != "") { _GoodsReceivedLine = JsonConvert.DeserializeObject <List <ProformaInvoiceLine> >(HttpContext.Session.GetString("listadoproductosproformainvoice")); _existelinea = _GoodsReceivedLine.Where(q => q.ProformaLineId == _ProformaInvoiceLinep.ProformaLineId).ToList(); } var id = _ProformaInvoiceLinep.ProformaLineId; if (_GoodsReceivedLine.Count > 0) { id--; foreach (var item in _GoodsReceivedLine) { if (item.ProductId == _ProformaInvoiceLinep.ProductId) { item.Quantity = item.Quantity + _ProformaInvoiceLinep.Quantity; item.Amount = item.Amount + _ProformaInvoiceLinep.Amount; HttpContext.Session.SetString("listadoproductosproformainvoice", JsonConvert.SerializeObject(_GoodsReceivedLine).ToString()); break; } else if (item.ProformaLineId == id && _existelinea.Count == 0) { _GoodsReceivedLine.Add(_ProformaInvoiceLinep); HttpContext.Session.SetString("listadoproductosproformainvoice", JsonConvert.SerializeObject(_GoodsReceivedLine).ToString()); break; } } } else if (_ProformaInvoiceLinep.ProformaLineId > 0 && _existelinea.Count == 0) { _GoodsReceivedLine.Add(_ProformaInvoiceLinep); HttpContext.Session.SetString("listadoproductosproformainvoice", JsonConvert.SerializeObject(_GoodsReceivedLine).ToString()); } else { var obj = _GoodsReceivedLine.Where(x => x.ProformaLineId == _ProformaInvoiceLinep.ProformaLineId).FirstOrDefault(); if (obj != null) { obj.Description = _ProformaInvoiceLinep.Description; obj.Price = _ProformaInvoiceLinep.Price; obj.Quantity = _ProformaInvoiceLinep.Quantity; obj.Amount = _ProformaInvoiceLinep.Amount; obj.SubProductId = _ProformaInvoiceLinep.SubProductId; obj.SubProductName = _ProformaInvoiceLinep.SubProductName; obj.SubTotal = _ProformaInvoiceLinep.SubTotal; obj.TaxAmount = _ProformaInvoiceLinep.TaxAmount; obj.TaxCode = _ProformaInvoiceLinep.TaxCode; //obj.TaxId = _ProformaInvoiceLinep.TaxId; obj.TaxPercentage = _ProformaInvoiceLinep.TaxPercentage; obj.UnitOfMeasureId = _ProformaInvoiceLinep.UnitOfMeasureId; obj.UnitOfMeasureName = _ProformaInvoiceLinep.UnitOfMeasureName; obj.WareHouseId = _ProformaInvoiceLinep.WareHouseId; obj.CenterCostId = _ProformaInvoiceLinep.CenterCostId; obj.DiscountAmount = _ProformaInvoiceLinep.DiscountAmount; obj.DiscountPercentage = _ProformaInvoiceLinep.DiscountPercentage; obj.Total = _ProformaInvoiceLinep.Total; } HttpContext.Session.SetString("listadoproductosproformainvoice", JsonConvert.SerializeObject(_GoodsReceivedLine).ToString()); } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } return(_GoodsReceivedLine.ToDataSourceResult(request)); }