public AcknowledgementInherit <Combo> GetCombo(int id) { var ack = new AcknowledgementInherit <Combo>(); ack.isSuccess = true; ack.Data = db.Comboes.Find(id); if (ack.Data == null) { ack.isSuccess = false; } return(ack); }
public AcknowledgementInherit <List <ComboGroup> > GetComboGroups() { var ack = new AcknowledgementInherit <List <ComboGroup> >(); ack.Data = db.ComboGroups.ToList(); if (ack.Data.Count() > 0) { ack.isSuccess = true; } else { ack.isSuccess = false; } return(ack); }
public AcknowledgementInherit <ComboesComboTypesViewModel> GetComboesAndComboTypes(int index = 1, int PageSize = 15) { var ack = new AcknowledgementInherit <ComboesComboTypesViewModel>(); ack.isSuccess = true; ack.Data = new ComboesComboTypesViewModel(); AcknowledgementInherit <List <ComboType> > ackComboTypes = GetComboTypes(); ack.Data.ComboTypes = ackComboTypes.Data; ack.isSuccess = ackComboTypes.isSuccess; AcknowledgementInherit <ComboesViewModel> ackComboes = GetComboes(ack.Data.ComboTypes[0].Id, index, PageSize); ack.Data.Comboes = ackComboes.Data; ack.isSuccess = ackComboes.isSuccess; return(ack); }
public AcknowledgementInherit <BillViewModel> SearchBill(int orderId = 0, string email = "") { var ack = new AcknowledgementInherit <BillViewModel>(); ack.isSuccess = true; var condition = $"CustomerEmail.Contains(\"{email}\") && Id=={orderId}"; var query = System.Linq.Dynamic.DynamicQueryable.Where(db.Orders.AsQueryable(), condition).SingleOrDefault(); if (query != null) { var dataReturn = new BillViewModel(); dataReturn.order = query; var store = db.Stores.SingleOrDefault(p => p.Id == query.StoreId); dataReturn.store = store; var comboOrderList = db.OrderComboes.Where(p => p.OrderId == orderId) .Join(db.Comboes, o => o.ComboId, c => c.Id, (o, c) => new ComboOrderView() { comboName = c.Name, orderCombo = o }) .ToList(); dataReturn.comboOrderList = comboOrderList; ack.Data = dataReturn; } else { ack.isSuccess = false; } return(ack); }
public AcknowledgementInherit <List <BillViewModel> > CreateOrder(OrderViewModel data) { var dataReturn = new List <BillViewModel>(); foreach (var p in data.cartGroup) { Order order = new Order() { CustomerName = data.customerInform.Name, CustomerPhone = data.customerInform.Phone, CustomerEmail = data.customerInform.Email, CustomerAddressId = 1,// gán đại CardNumber = (data.customerInform.KHTT != null)? data.customerInform.KHTT.ToString(): "", SendToCustomer = data.customerInform.isReceiver, ReceiverName = (!data.customerInform.isReceiver) ? data.receiverInform.Name : data.customerInform.Name, ReceiverPhone = (!data.customerInform.isReceiver) ? data.receiverInform.Phone : data.customerInform.Phone, ReceiverEmail = (!data.customerInform.isReceiver) ? data.receiverInform.Email : data.customerInform.Email, ReceiverAddressId = (!data.customerInform.isReceiver) ? 1 : 0,//gán đại nếu có giá trị thì gán thật TotalPrice = p.Sum(o => o.comboInform.combo.TotalPrice * o.quantity), PaidPrice = p.Sum(o => o.comboInform.combo.TotalPrice * o.quantity) / 2, Status = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now, StoreId = p[0].storeId, DeliveryTime = p[0].dateDelivery, Charge = 0, //gán đại StringId = "a", //gán đại Distance = 10, // gán đại EventId = 1, //gán đại MinimumPaymentRequire = 0 // gán đại }; db.Orders.Add(order); db.SaveChanges(); //tạo order để lấy orderId, order lúc này có tổng tiền bằng 0 var comboOrderViewList = new List <ComboOrderView>(); //biến tính tổng tiền để gán lại cho order //var tongTienMoiHD = 0; //vòng lặp tạo ordercombo foreach (var x in p) { OrderCombo orderCombo = new OrderCombo() { OrderId = order.Id, ComboId = x.comboInform.combo.Id, Quantity = x.quantity, UnitPrice = x.comboInform.combo.TotalPrice, Note = x.note }; db.OrderComboes.Add(orderCombo); db.SaveChanges(); //dataReturn //gán ordercombo để trả về client var comboOrderView = new ComboOrderView() { orderCombo = orderCombo, comboName = db.Comboes.Find(orderCombo.ComboId).Name }; comboOrderViewList.Add(comboOrderView); //tongTienMoiHD += x.quantity * x.comboInform.combo.TotalPrice; } ////gán lại totalPrice cho order //order.TotalPrice = tongTienMoiHD; //order.PaidPrice = tongTienMoiHD / 2; //db.SaveChanges(); // gán bill để trả về client var d = new BillViewModel() { order = order, comboOrderList = comboOrderViewList, store = db.Stores.Find(order.StoreId) }; dataReturn.Add(d); } var ack = new AcknowledgementInherit <List <BillViewModel> >(); ack.isSuccess = true; ack.Data = dataReturn; return(ack); }
public AcknowledgementInherit <ComboesViewModel> GetComboes(int typeProduct = 1, int index = 1, int PageSize = 15, string stringSearch = "") { var ack = new AcknowledgementInherit <ComboesViewModel>(); ack.isSuccess = true; ack.Data = new ComboesViewModel(); ack.Data.comboInformList = new List <ComboInform>(); var eventCombo = db.EventComboTypes.Where(p => p.ComboTypeId == typeProduct).AsQueryable(); var comboGroup = db.ComboGroups.Join(eventCombo, g => g.Id, e => e.Id, (g, e) => g).AsQueryable(); var comboes = db.Comboes.Join(comboGroup, p => p.ComboGroupId, g => g.Id, (p, g) => p) .Where(p => p.IsDisabled == false).AsQueryable(); if (stringSearch != "") { var condition = $"Name.Contains(\"{stringSearch}\")"; var query = comboes; comboes = System.Linq.Dynamic.DynamicQueryable.Where(query, condition); } var pagingData = new PagingData() { PageIndex = index, PageSize = PageSize, ItemTotal = comboes.Count() }; ack.Data.PageIndex = index; ack.Data.MaxPage = pagingData.PageTotal; var comboList = comboes.OrderBy(p => p.Id) .Skip(pagingData.GetSkipNumber()) .Take(PageSize).ToList(); foreach (var c in comboList) { // tên của storeGroup/ id của store và name của store //danh sách id storegroup của combo var comboStoreGroupList = db.ComboStoreGroups.Where(p => p.ComboId == c.Id).AsQueryable(); //danh sách name của storeGroup của combo var nameStoreGroupList = db.StoreGroups.Join(comboStoreGroupList, s => s.Id, p => p.StoreGroupId, (s, p) => s.Name).ToList(); //danh sách id Store của storeGroup var storeGroupDetails = db.StoreGroupDetails.Join(comboStoreGroupList, s => s.StoreGroupId, cs => cs.StoreGroupId, (s, cs) => s).AsQueryable(); //danh sách store var storeList = db.Stores.Join(storeGroupDetails, s => s.Id, g => g.StoretId, (s, g) => s).AsQueryable(); var comboInform = new ComboInform() { combo = c, storeGroupList = nameStoreGroupList, storeList = storeList.ToList() }; ack.Data.comboInformList.Add(comboInform); } //ack.Data.comboList = comboes.OrderBy(p => p.Id) // .Skip(pagingData.GetSkipNumber()) // .Take(PageSize).ToList(); //if (ack.Data.comboList.Count() <= 0) ack.isSuccess = false; return(ack); }