public static void CreateAccount(Guid? AccountNumber, Price _object, DataClasses1DataContext dbContext, bool withLocation = false) { if (AccountNumber != null) { IQueryable<PriceAccount> myAccount = null; if (withLocation == false) { myAccount = dbContext.PriceAccount.Where(q => q.PriceId == _object.Id && q.Price.LocationId == null); } else { myAccount = dbContext.PriceAccount.Where(q => q.PriceId == _object.Id && q.Price.LocationId == _object.LocationId); } if (myAccount.Count() > 0) { dbContext.PriceAccount.DeleteAllOnSubmit<PriceAccount>(myAccount); dbContext.SubmitChanges(); } if (myAccount.Count() == 0) { var myNewAccount = new PriceAccount { PriceId = _object.Id, AccountId = AccountNumber.Value }; dbContext.PriceAccount.InsertOnSubmit(myNewAccount); dbContext.SubmitChanges(); } } }
/// <summary> /// Erstellt einen neuen Preis. /// </summary> /// <param name="amount">Der Betrag des Preises.</param> /// <param name="authorativeCharge">Die behoerdliche Gebuehr.</param> /// <param name="productId">Id des Produkts, für den der Preis gilt.</param> /// <param name="locationId">Id des Standorts, falls benoetigt. </param> /// <param name="dbContext">Datenbankkontext für die Transaktion.</param> /// <returns>Den neuen Preis.</returns> public static Price CreatePrice(decimal amount, decimal? authorativeCharge, int productId, int? locationId, int? accountId, DataClasses1DataContext dbContext) { if (dbContext.Price.Any(q => q.ProductId == productId && q.LocationId == locationId)) { throw new Exception("Für dieses Produkt und diesen Standort ist bereits ein Preis eingetragen."); } var productName = dbContext.Product.Single(q => q.Id == productId).Name; string standortText = string.Empty; if (locationId.HasValue) { standortText = " und Standort " + dbContext.Location.Single(q => q.Id == locationId).Name; } var price = new Price() { Amount = amount, AuthorativeCharge = authorativeCharge, LocationId = locationId, ProductId = productId, }; dbContext.Price.InsertOnSubmit(price); dbContext.SubmitChanges(); dbContext.WriteLogItem("Preis für Produkt " + productName + standortText + " eingetragen.", LogTypes.INSERT, price.Id, "Price"); if (accountId.HasValue) { var account = new PriceAccount() { Price = price, AccountId =accountId.Value }; dbContext.PriceAccount.InsertOnSubmit(account); dbContext.SubmitChanges(); dbContext.WriteLogItem("Account für Produkt " + productName + standortText + " eingetragen.", LogTypes.INSERT, price.Id, "Price"); } return price; }
/// <summary> /// Erstellt ein neues Produkt. /// </summary> /// <param name="name">Name des Produkts.</param> /// <param name="productCategoryId">Id der Produktkategorie, falls gewünscht.</param> /// <param name="priceAmount">Standardpreis des Produkts.</param> /// <param name="authorativeCharge">Standardmäßge behördliche Gebühr, falls gewünscht.</param> /// <param name="itemNumber">Artikelnummer des Produkts.</param> /// <param name="needsVAT">Gibt an, ob das Produkt mehrwertsteuerpflichtig ist oder nicht.</param> /// <param name="orderTypeId">Id der Auftragsart.</param> /// <param name="registrationOrderTypeId">Id der Zulassungsauftragsart, falls benötigt.</param> /// <param name="dbContext">Datenbankkontext für die Transaktion.</param> /// <returns>Das neue Produkt.</returns> public static Product CreateProduct(string name, int? productCategoryId, decimal priceAmount, decimal? authorativeCharge, string itemNumber, int orderTypeId, int? registrationOrderTypeId, bool needsVAT, DataClasses1DataContext dbContext) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Der Name darf nicht leer sein."); } if (string.IsNullOrEmpty(itemNumber)) { throw new ArgumentException("Die Artikelnummer darf nicht leer sein."); } var product = new Product() { Name = name, ProductCategoryId = productCategoryId, ItemNumber = itemNumber, OrderTypeId = orderTypeId, RegistrationOrderTypeId = registrationOrderTypeId, NeedsVAT = needsVAT, IsLocked = false, _dbContext = dbContext }; var price = new Price() { Amount = priceAmount, AuthorativeCharge = authorativeCharge, }; product.Price.Add(price); dbContext.Product.InsertOnSubmit(product); dbContext.SubmitChanges(); dbContext.WriteLogItem("Produkt " + name + " wurde angelegt.", LogTypes.INSERT, product.Id, "Product"); return product; }
/// <summary> /// Loescht Eintraege aus der Preisliste /// </summary> /// <param name="Price[]">Preisliste</param> /// <param name="callFromProduct"></param> /// <param name="dbContext"></param> public static void RemovePrice(Price[] pr, DataClasses1DataContext dbContext, bool callFromProduct = true) { foreach (var price in pr) { if (!callFromProduct && price.LocationId == null) { throw new Exception("Aus der Preisliste darf kein Standardpreis gelöscht werden!"); } var orders = (from order in dbContext.Order join orderserivce in dbContext.OrderItem on order.OrderNumber equals orderserivce.OrderNumber where (price.LocationId.HasValue ? order.LocationId == price.LocationId : order.LocationId == null) && orderserivce.ProductId == price.ProductId select new { order });//.ToList(); if (orders.ToList().Count() > 0) { throw new Exception("Löschen nicht möglich! Zu diesem Produkt: "+price.Product.Name+" mit dem Preis: "+price.Amount+ " bereits Auftragspositionen vorhanden!"); } var priceAccount = dbContext.PriceAccount.Where(q => q.PriceId == price.Id); dbContext.PriceAccount.DeleteAllOnSubmit(priceAccount); dbContext.WriteLogItem("PriceAccounts mit der Id:" + price.Id + " wurden gelöscht.", LogTypes.DELETE, price.Id, "PriceAccounts"); var customerProducts = dbContext.CustomerProduct.Where(q => q.ProductId == price.ProductId); dbContext.CustomerProduct.DeleteAllOnSubmit(customerProducts); dbContext.WriteLogItem("CustomerProduct mit der Id:" + price.ProductId + " wurden gelöscht.", LogTypes.DELETE, price.Id, "CustomerProduct"); dbContext.Price.DeleteOnSubmit(price); dbContext.WriteLogItem("Price mit der Id:" + price.Id + " wurde gelöscht.", LogTypes.DELETE, price.Id, "Id"); } }
private void attach_Price(Price entity) { this.SendPropertyChanging(); entity.Location = this; }
private void detach_Price(Price entity) { this.SendPropertyChanging(); entity.Location = null; }
partial void DeletePrice(Price instance);
partial void UpdatePrice(Price instance);
partial void InsertPrice(Price instance);
private void detach_Price(Price entity) { this.SendPropertyChanging(); entity.Product = null; }
private void attach_Price(Price entity) { this.SendPropertyChanging(); entity.Product = this; }