public DiscountModel GetDiscountModel(Guid id) { using (var connectionScope = new ConnectionScope()) { var result = new DiscountModel(); result.Discount = connectionScope.Connection.Get<Discount>(id); result.Products = connectionScope.Connection.GetList<DiscountProduct>(Predicates.Field<DiscountProduct>(f => f.DiscountId, Operator.Eq, id)).ToList(); result.Customers = connectionScope.Connection.GetList<DiscountCustomer>(Predicates.Field<DiscountCustomer>(f => f.DiscountId, Operator.Eq, id)).ToList(); return result; } }
public DiscountModel InsertDiscountModel(DiscountModel entity) { // TODO - Make this more efficient. using (var connectionScope = new ConnectionScope()) { connectionScope.Connection.Insert<Discount>(entity.Discount); foreach (var product in entity.Products) product.DiscountId = entity.Discount.Id; foreach (var customer in entity.Customers) customer.DiscountId = entity.Discount.Id; connectionScope.Connection.Insert<DiscountProduct>(entity.Products); connectionScope.Connection.Insert<DiscountCustomer>(entity.Customers); } return entity; }
public DiscountModel UpdateDiscountModel(DiscountModel entity) { // TODO - Make this more efficient. using (var connectionScope = new ConnectionScope()) { connectionScope.Connection.Delete<DiscountProduct>(Predicates.Field<DiscountProduct>(f => f.DiscountId, Operator.Eq, entity.Discount.Id)); connectionScope.Connection.Delete<DiscountCustomer>(Predicates.Field<DiscountCustomer>(f => f.DiscountId, Operator.Eq, entity.Discount.Id)); connectionScope.Connection.Update<Discount>(entity.Discount); foreach (var product in entity.Products) product.DiscountId = entity.Discount.Id; foreach (var customer in entity.Customers) customer.DiscountId = entity.Discount.Id; connectionScope.Connection.Insert<DiscountProduct>(entity.Products); connectionScope.Connection.Insert<DiscountCustomer>(entity.Customers); } return entity; }
public DiscountModel UpdateDiscountModel(DiscountModel entity) { return Manager.UpdateDiscountModel(entity); }
public DiscountModel InsertDiscountModel(DiscountModel entity) { return Manager.InsertDiscountModel(entity); }
public void Save() { var model = new DiscountModel { Discount = new Discount { Description = Description }, Products = new List<DiscountProduct>(DiscountProducts.Where(o => o.Discount > 0.0m).Select(o => o.DiscountProduct)), Customers = new List<DiscountCustomer>(DiscountCustomers.Where(o => o.Selected).Select(o => o.DiscountCustomer)) }; DiscountService.InsertDiscountModel(model); Close(); }