private static Price findPrice(RegistrationNeuzulassungHeader neuzulassung) { DataClasses1DataContext dbContext = new DataClasses1DataContext(); Guid? locationId = null; Price newPrice = null; if (!String.IsNullOrEmpty(neuzulassung.ProductCostCenterList[0].ProductId)) { if (!String.IsNullOrEmpty(neuzulassung.LocationId)) { locationId = new Guid(neuzulassung.LocationId); newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == new Guid(neuzulassung.ProductCostCenterList[0].ProductId) && q.LocationId == locationId); } if (String.IsNullOrEmpty(neuzulassung.LocationId) || newPrice == null) { newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == new Guid(neuzulassung.ProductCostCenterList[0].ProductId) && q.LocationId == null); } } return newPrice; }
/// <summary> /// Prüfe ob die Guids im Header, auch im System vorhanden sind /// </summary> /// <param name="header"></param> /// <returns></returns> private static string ValidateGuid(RegistrationNeuzulassungHeader header, DataClasses1DataContext dbContext) { Customer cust = dbContext.Customer.SingleOrDefault(q=>q.Id==new Guid(header.CustomerId)); if (cust == null) { return "Unbekannter Kunde"; } Location loc = dbContext.Location.SingleOrDefault(q => q.Id == new Guid(header.LocationId) && q.CustomerId == new Guid(header.CustomerId)); if (loc == null) { return "Unbekannte LocationId bei diesem Kunden"; } foreach (var costProdPair in header.ProductCostCenterList) { CostCenter cost = dbContext.CostCenter.SingleOrDefault(q => q.Id == new Guid(costProdPair.CostCenterId) && q.CustomerId == new Guid(header.CustomerId)); if (cost == null) { return "Unbekannter Standort(Kostenstelle) bei diesem Kunden"; } } foreach (var costProdPair in header.ProductCostCenterList) { Product product = dbContext.Product.SingleOrDefault(q => q.Id == new Guid(costProdPair.ProductId)); if (product == null) { return "Unbekannte ProductId"; } } return string.Empty; }
private static void AddAnotherProducts(RegistrationOrder regOrd, Guid? locationId, RegistrationNeuzulassungHeader ProductCostCenterListHeader, Guid currentUserId) { bool allesHatGutGelaufen = false; string ProduktId = ""; string CostCenterId = ""; int skipFirst = 0; foreach (var productCostCenterPair in ProductCostCenterListHeader.ProductCostCenterList) { if (skipFirst > 0) { if (!String.IsNullOrEmpty(productCostCenterPair.ProductId) && !String.IsNullOrEmpty(productCostCenterPair.CostCenterId)) { try { DataClasses1DataContext dbContext = new DataClasses1DataContext(currentUserId); Guid orderId = regOrd.OrderId; Price newPrice; OrderItem newOrderItem1 = null; ProduktId = productCostCenterPair.ProductId; CostCenterId = productCostCenterPair.CostCenterId; if (!String.IsNullOrEmpty(ProduktId)) { Guid productId = new Guid(ProduktId); Guid costCenterId = Guid.Empty; KVSCommon.Database.Product newProduct = dbContext.Product.SingleOrDefault(q => q.Id == productId); if (locationId == null) //small { newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null); } else //large { costCenterId = new Guid(CostCenterId); newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == locationId); if (newPrice == null) newPrice = dbContext.Price.SingleOrDefault(q => q.ProductId == newProduct.Id && q.LocationId == null); } var orderToUpdate = dbContext.Order.SingleOrDefault(q => q.Id == orderId); orderToUpdate.LogDBContext = dbContext; if (orderToUpdate != null) { newOrderItem1 = orderToUpdate.AddOrderItem(newProduct.Id, newPrice.Amount, 1, costCenterId, null, false, dbContext); if (newPrice.AuthorativeCharge.HasValue) { orderToUpdate.AddOrderItem(newProduct.Id, newPrice.AuthorativeCharge.Value, 1, costCenterId, newOrderItem1.Id, newPrice.AuthorativeCharge.HasValue, dbContext); } dbContext.SubmitChanges(); allesHatGutGelaufen = true; } } if (allesHatGutGelaufen) dbContext.SubmitChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } } } else { skipFirst = 1; } } }
/// <summary> /// Prüfe ob die Guids im Header, auch Guids sind /// </summary> /// <param name="header"></param> /// <returns></returns> private static bool ValidateGuid(RegistrationNeuzulassungHeader header) { try { Guid aG = new Guid(header.CustomerId); } catch { return false; } try { foreach (var prodCostPair in header.ProductCostCenterList) { Guid aG = new Guid(prodCostPair.CostCenterId); } } catch { return false; } try { Guid aG = new Guid(header.LocationId); } catch { return false; } try { foreach (var prodCostPair in header.ProductCostCenterList) { Guid aG = new Guid(prodCostPair.ProductId); } } catch { return false; } return true; }