Example #1
0
 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();
        }
        }
 }
Example #2
0
        /// <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;
        }
Example #3
0
        public static void CreateAccount(string accountNumber, Guid PriceId, DataClasses1DataContext dbContext)
        {
            var account = dbContext.Accounts.FirstOrDefault(s => s.AccountNumber == accountNumber && s.CustomerId == null);
                Accounts acc = null;
                if (account == null)
                {
                    acc = Accounts.CreateAccount(null, accountNumber, dbContext);

                }

                if (dbContext.PriceAccount.FirstOrDefault(q => q.PriceId == PriceId && q.AccountId == ((account != null) ? account.AccountId : acc.AccountId)) == null)
                {
                    var myNewAccount = new PriceAccount
                    {
                        PriceId = PriceId,
                        AccountId = ((account != null) ? account.AccountId : acc.AccountId)
                    };

                    dbContext.PriceAccount.InsertOnSubmit(myNewAccount);
                    dbContext.SubmitChanges();

                }
        }
Example #4
0
 partial void DeletePriceAccount(PriceAccount instance);
Example #5
0
 partial void UpdatePriceAccount(PriceAccount instance);
Example #6
0
 partial void InsertPriceAccount(PriceAccount instance);
Example #7
0
		private void detach_PriceAccount(PriceAccount entity)
		{
			this.SendPropertyChanging();
			entity.Accounts = null;
		}
Example #8
0
		private void attach_PriceAccount(PriceAccount entity)
		{
			this.SendPropertyChanging();
			entity.Accounts = this;
		}