public void Update(BONUS Bonus) { _bonusDAO.Update(Bonus); Context.SaveChanges(); }
public string Insert(ORDERS Order, bool FrontEnd, bool SaveContext = true) { string retString = String.Empty; //if there is any used bonus, decrease the remainder if (Order.ORDER_BONUS.Count > 0) { BONUS bonus; foreach (ORDER_BONUS bon in Order.ORDER_BONUS) { bonus = _bonusDAO.GetById(bon.BonusID); // object must be detached from context, otherwise Version field for concurrency check will not be updated!!! Context.BONUS.Detach(bonus); // using the version that was initially retrieved from db // if another user modified this record an OptimisticConcurrencyException will be raised if (bon.Value > bonus.ValueRemainder) { //TODO think what to do with version //bonus.Version = bon.BONUS.Version; throw new System.Data.OptimisticConcurrencyException("Bonus not sufficient."); } bonus.ValueRemainder -= bon.Value; _bonusDAO.Update(bonus); bon.BONUS = null; } } CUSTOMER customer = _customerDAO.GetById(Order.CustomerID.Value); // for electronic payments insert directly if ((Order.PAYMENT.Type == (int)PaymentType.PP && Order.PAYMENT.PAYPAL_PAYMENT.TransactionStatus == "Completed") || (Order.PAYMENT.Type == (int)PaymentType.EP && Order.PAYMENT.EASYPAY_PAYMENT.TransactionStatus == "Success") || (Order.PAYMENT.Type == (int)PaymentType.CA && !FrontEnd && Order.Completed)) { if (!customer.FirstBuy.HasValue || !customer.FirstBuy.Value) { // set first buy of user customer.FirstBuy = true; _customerDAO.Update(customer, true, false); // first buy of this customer & invited by someone if (customer.InvitedFrom.HasValue) { insertCustomerBonus(customer); retString = "Bonus added to inviter " + customer.CUSTOMER2.Email; Util.Mailer.SendBonus(customer, customer.CUSTOMER2.Email, Configuration.BonusValue + " € bonus per ju ne FZone"); } } } Guid g = Guid.NewGuid(); UniqueIdGenerator unique = UniqueIdGenerator.GetInstance(); string vNum = unique.GetBase32UniqueId(g.ToByteArray(), 20).ToLower(); Order.VerificationNumber = vNum; _orderDAO.Insert(Order); // payment if (Order.PAYMENT != null) { Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT, EntityState.Added); if (Order.PAYMENT.Type == (int)PaymentType.CA) { Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT.CASH_PAYMENT, System.Data.EntityState.Added); } else if (Order.PAYMENT.Type == (int)PaymentType.PP) { Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT.PAYPAL_PAYMENT, System.Data.EntityState.Added); } else if (Order.PAYMENT.Type == (int)PaymentType.EP) { Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT.EASYPAY_PAYMENT, System.Data.EntityState.Added); } } if (SaveContext) { Context.SaveChanges(); } return(retString); }