public List<BONUS> Search(BONUS Bonus, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection) { var result = Context.BONUS.AsQueryable(); if (Bonus != null) { if (Bonus.ID != 0) { result = result.Where(b => b.ID == Bonus.ID); } if (!String.IsNullOrEmpty(Bonus.Description)) { result = result.Where(b => b.Description.Contains(Bonus.Description)); } if (Bonus.CustomerID.HasValue) { result = result.Where(b => b.CustomerID == Bonus.CustomerID.Value); } if (!String.IsNullOrWhiteSpace(Bonus.CustomerFullName)) { result = result.Where(s => (s.CUSTOMER.Name + " " + s.CUSTOMER.Surname).Contains(Bonus.CustomerFullName)); } // useful for filtering expired bonuses if (Bonus.Validity.HasValue) { result = result.Where(b => b.Validity >= Bonus.Validity); } if (Bonus.CustomerID.HasValue) { result = result.Where(b => b.CustomerID == Bonus.CustomerID); } } TotalRecords = result.Count(); if (!String.IsNullOrEmpty(OrderExp) && OrderExp.Equals("CustomerFullName")) { if (SortDirection == SortDirection.Ascending) result = result.OrderBy(c => c.CUSTOMER.Name).ThenBy(c => c.CUSTOMER.Surname); else result = result.OrderByDescending(c => c.CUSTOMER.Name).ThenBy(c => c.CUSTOMER.Surname); } else { GenericSorterCaller<BONUS> sorter = new GenericSorterCaller<BONUS>(); result = sorter.Sort(result, string.IsNullOrEmpty(OrderExp) ? DEFAULT_ORDER_EXP : OrderExp, SortDirection); } // pagination return result.Skip(PageIndex * PageSize).Take(PageSize).ToList(); }
private void FixupBONUS(BONUS previousValue) { if (previousValue != null && previousValue.ORDER_BONUS.Contains(this)) { previousValue.ORDER_BONUS.Remove(this); } if (BONUS != null) { if (!BONUS.ORDER_BONUS.Contains(this)) { BONUS.ORDER_BONUS.Add(this); } if (BonusID != BONUS.ID) { BonusID = BONUS.ID; } } }
public void Delete(BONUS delBonus) { BONUS bon = Context.BONUS.Where(b => b.ID == delBonus.ID).FirstOrDefault(); Context.DeleteObject(bon); }
public void Update(BONUS upBonus) { Context.BONUS.Attach(upBonus); Context.ObjectStateManager.ChangeObjectState(upBonus, System.Data.EntityState.Modified); }
public void Insert(BONUS newBonus) { Context.BONUS.AddObject(newBonus); }
public void DeleteById(int Id) { BONUS obj = new BONUS() { ID = Id }; Delete(obj); }
private void setBonus(ORDERS order, int bonusID, decimal BonusUsed) { BONUS bonus = new BONUS() { ID = bonusID }; ORDER_BONUS ordBonus = new ORDER_BONUS() { OrderID = order.ID, BonusID = bonusID, Value = BonusUsed, ORDERS = order, BONUS = bonus }; order.BonusUsed = BonusUsed; order.ORDER_BONUS.Add(ordBonus); }
private void setBonus(ORDERS order) { int bonusID = 0; if (Int32.TryParse(ddlBonus.SelectedValue, out bonusID) && bonusID != -1) { BONUS bonus = new BONUS() { ID = bonusID, Version = Version.Where(b => b.Key == bonusID).FirstOrDefault().Value }; ORDER_BONUS ordBonus = new ORDER_BONUS() { OrderID = order.ID, BonusID = bonusID, Value = BonusUsed, ORDERS = order, BONUS = bonus }; order.BonusUsed = BonusUsed; order.ORDER_BONUS.Add(ordBonus); } }
protected void dataBindBonus(string sortExp, int pageIndex) { try { int totalRecords = 0; gridBonus.PageSize = Utils.Configuration.PageSize; int id = 0; BONUS bonus = new BONUS() { CustomerID = this.CustomerID }; List<BONUS> list = ApplicationContext.Current.Bonuses.Search(bonus, Utils.Configuration.PageSize, pageIndex, out totalRecords, sortExp, gridBonus.SortOrder); gridBonus.DataSource = list; gridBonus.CustomCustomVirtualItemCount = totalRecords; gridBonus.DataBind(); } catch (Exception e) { writeError(e.Message); } }
public void Delete(BONUS Bonus) { _bonusDAO.Delete(Bonus); Context.SaveChanges(); }
public void Update(BONUS Bonus) { _bonusDAO.Update(Bonus); Context.SaveChanges(); }
public void Insert(BONUS Bonus) { _bonusDAO.Insert(Bonus); Context.SaveChanges(); }
public List<BONUS> Search(BONUS Bonus, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection) { return _bonusDAO.Search(Bonus, PageSize, PageIndex, out TotalRecords, OrderExp, SortDirection); }
public void CancelOrderById(int OrderId) { ORDERS order = _orderDAO.GetById(OrderId); PRODUCT_ATTRIBUTE prodAttr; // put back to the warehouse each product that was in the order // version is not needed as the availability is incremented, so no risk foreach (ORDER_DETAIL item in order.ORDER_DETAIL) { prodAttr = null; prodAttr = _productDAO.GetProductAttributeById(item.ProdAttrID); prodAttr.Availability += item.Quantity; _productDAO.UpdateProductAttribute(prodAttr, false); } order.Canceled = true; order.Completed = false; order.Status = 6; _orderDAO.Update(order, false); // TODO Revert BONUS if (order.BonusUsed.HasValue && order.BonusUsed.Value > 0) { decimal usedValue = 0; foreach (ORDER_BONUS b in order.ORDER_BONUS) { usedValue += b.Value.Value; } DateTime validity = order.ORDER_BONUS.Max(b => b.BONUS.Validity).Value; BONUS bon = new BONUS() { CustomerID = order.CustomerID, DateAssigned = DateTime.Today, Validity = validity, Description = "Per anullim porosie", Value = usedValue, ValueRemainder = usedValue }; _bonusDAO.Insert(bon); } Context.SaveChanges(); }
private void insertCustomerBonus(CUSTOMER customer) { BONUS b = new BONUS() { CustomerID = customer.InvitedFrom.Value, DateAssigned = DateTime.Today, Validity = DateTime.Today.AddMonths(2), Description = "Per ftesen e " + customer.Email, Value = Configuration.BonusValue, ValueRemainder = Configuration.BonusValue }; _bonusDAO.Insert(b); }