Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C# by Diego ( 8 years ago )
public void CopyErpOrderToDataAccessOrder(MainRetailWebService.Model.GetPedidoInfo orderAPI, DataAccess.Models.OMS.OMS_Order orderDB, NaveWebContext context)
{
if (orderDB.DateCreated != orderAPI.DataPedido) orderDB.DateCreated = orderAPI.DataPedido;
if (orderDB.ExternalId != orderAPI.CodigoVenda) orderDB.ExternalId = orderAPI.CodigoVenda;
int hashorderAPI = orderAPI.Itens.Sum(q => q.IDSku * (int)((q.PrecoVenda-q.Desconto/q.Quantidade)*10) * q.Quantidade);
int hashOrderDB = (orderDB.Items==null || orderDB.Items.Any(q=>q.Sku==null))?-1:orderDB.Items.Sum(q => q.Sku.ExternalId * (int)(q.UnitPrice * 10) * q.Quantity);
if (hashorderAPI != hashOrderDB)
{
if (orderDB.Items == null)
{
orderDB.Items = new List<DataAccess>();
}
var dic = new Dictionary<OrderItemAux>();
foreach (var item in orderAPI.Itens)//
{
var ItemAux = new OrderItemAux() { Cost = item.PrecoVenda-item.Desconto/item.Quantidade, IdSku = item.IDSku, Quantity = item.Quantidade };
if (dic.ContainsKey(ItemAux) == false)
{
dic.Add(ItemAux, 1);
}
else
{
dic[ItemAux]++;
}
}
foreach(var item in orderDB.Items)
{
var ItemAux = new OrderItemAux() { Cost = item.UnitPrice, IdSku = item.Sku==null?-1:item.Sku.ExternalId, Quantity = item.Quantity };
if (dic.ContainsKey(ItemAux) == false)
{
dic.Add(ItemAux, -1);
}
else
{
dic[ItemAux]--;
}
}
foreach(var item in dic)
{
if (item.Value > 0)//está na API e não está no DB
{
for(int i=0; i<item xss=removed xss=removed xss=removed xss=removed xss=removed> q.ExternalId == item.Key.IdSku);
if (skuInDb == null)
{
itemDB.Sku_ID_No_Matching = item.Key.IdSku;
}
else
{
itemDB.Sku = skuInDb;
}
orderDB.Items.Add(itemDB);
}
}else if (item.Value < 0 xss=removed xss=removed> q.Quantity == item.Key.Quantity && (q.Sku == null || q.Sku.ExternalId == item.Key.IdSku) && q.UnitPrice == item.Key.Cost);
var objsToRemove = allObjs.Take(Math.Abs(item.Value)).ToList();
//objsToRemove.ForEach(q => order.Items.Remove(q));
context.Set<DataAccess>().RemoveRange(objsToRemove);
}
}
}
if (orderDB.Tracking == null) orderDB.Tracking = new DataAccess.Models.OMS.Tracking();
if(orderDB.ShippingAddress == null) orderDB.ShippingAddress = new DataAccess.Models.OMS.OMS_Address();
var addOrder = orderDB.ShippingAddress;
var addInfo = orderAPI.Cliente.EnderecoEntrega;
var phone1 = (orderAPI.Cliente.TelefoneResidencial.Ddd + orderAPI.Cliente.TelefoneCelular.Numero).Trim();
var phone2 = (orderAPI.Cliente.TelefoneResidencial.Ddd + orderAPI.Cliente.TelefoneResidencial.Numero).Trim(); ;
if (addOrder.CityName != addInfo.DescricaoMunicipio) addOrder.CityName = addInfo.DescricaoMunicipio;
if (addOrder.Comment != addInfo.Complemento) addOrder.Comment = addInfo.Complemento;
if (addOrder.Neighbor != addInfo.Bairro) addOrder.Neighbor = addInfo.Bairro;
if (addOrder.Phone1 != phone1) addOrder.Phone1 = phone1;
if (addOrder.Phone2 != phone2) addOrder.Phone2 = phone2;
if (addOrder.PostalCode != addInfo.Cep) addOrder.PostalCode = addInfo.Cep;
if (addOrder.State != addInfo.SiglaEstado) addOrder.State = addInfo.SiglaEstado;
if (addOrder.StreetNumber != addInfo.Numero) addOrder.StreetNumber = addInfo.Numero;
if (addOrder.StreetName != addInfo.Logradouro) addOrder.StreetName = addInfo.Logradouro;
}
Revise this Paste