public IActionResult Edit(OrderDet orderDet) { OrderDet DbOrdDet = _context.OrderDets .Include(o => o.Order) .Include(o => o.Book) .FirstOrDefault(o => o.OrderDetID == orderDet.OrderDetID); Book book = _context.Books.FirstOrDefault(b => b.BookID == DbOrdDet.Book.BookID); int bookInv = book.Inventory; if (DbOrdDet.Quantity > bookInv) { return(View("AddError", new string[] { "Please select less than " + bookInv.ToString() })); } DbOrdDet.Quantity = orderDet.Quantity; DbOrdDet.TotalBookPrice = DbOrdDet.Quantity * DbOrdDet.Book.Price; if (ModelState.IsValid) { _context.OrderDets.Update(DbOrdDet); _context.SaveChanges(); return(RedirectToAction("Details", "Orders", new { id = DbOrdDet.Order.OrderID })); } return(View(orderDet)); }
public IActionResult AddToCart(OrderDet od) { Book book = _context.Books.Find(od.Book.BookID); od.Book = book; Order ord = _context.Orders.Find(od.Order.OrderID); od.Order = ord; od.TotalBookPrice = od.Book.Price * od.Quantity; int bookInv = book.Inventory; if (od.Quantity > bookInv) { return(View("AddError", new string[] { "Please select less than " + bookInv.ToString() })); } //katie added this to my invoice controller when there was no reason for the invoicedet modelstate to be invalid ModelState.Clear(); this.TryValidateModel(od); if (ModelState.IsValid) { _context.OrderDets.Add(od); _context.SaveChanges(); return(RedirectToAction("ShoppingCart")); } return(View("ShoppingCart")); }
private ClientDates PostNY(ClientDates clientD) { Console.WriteLine(clientD.dateS); var ordersNY = (from c in _context.Clientes join oNY in _context.OrdenesNewYork on c.IdCliente equals oNY.IdCliente where c.IdCliente == clientD.idClient select new { OrderId = oNY.IdOrden, IdCliente = c.IdCliente, FechasOrden = oNY.FechaOrden, RequiredDate = oNY.RequiredDate }).ToList(); int totalO = 0; foreach (var orders in ordersNY) { if (orders.FechasOrden >= clientD.dateS.Date && orders.FechasOrden <= clientD.dateE.Date) { OrderDet orderTemp = new OrderDet(); orderTemp.OrderId = orders.OrderId; orderTemp.FechasOrden = orders.FechasOrden; orderTemp.RequiredDate = orders.RequiredDate; clientD.orders.Add(orderTemp); totalO += 1; } } clientD.totalOrders = totalO; return(clientD); }
public static OrderDetModel ToModel(this OrderDet entity) { var model = new OrderDetModel() { Id = entity.Id, OrderId = entity.OrderId, StartDate = entity.StartDate, StartTime = entity.StartTime, EndDate = entity.EndDate, EndTime = entity.EndTime, IOHours = entity.IOHours, Description = entity.Description, Audit = entity.Audit ?? string.Empty, InformLeader = entity.InformLeader ?? false, WorkTransfer = entity.WorkTransfer ?? false, Recipient = entity.Recipient.HasValue ? entity.Recipient.Value : 0, }; using (var dbContext = new MissionskyOAEntities()) { UserService userServer = new UserService(); if (entity.Recipient != null) { var RecipientUser = userServer.GetUserDetail(entity.Recipient.Value); model.RecipientName = RecipientUser == null ? string.Empty : RecipientUser.EnglishName; } } model.StartDate = Convert.ToDateTime(entity.StartDate.ToShortDateString() + " " + entity.StartTime.ToString()); model.EndDate = Convert.ToDateTime(entity.EndDate.ToShortDateString() + " " + entity.EndTime.ToString()); return(model); }
public bool Add(OrderDet obj) { db = new StoreOlineEntities(); var tmp = db.OrderDets.SingleOrDefault(o => o.OrderID == obj.OrderID && o.ProductID == obj.ProductID); if (tmp != null) { return(false); } db.OrderDets.Add(obj); db.SaveChanges(); return(true); }
public ActionResult CreateOrder(PlaceOrderViewModel viewModel) { if (!ModelState.IsValid) { return(View("PlaceOrder", viewModel)); } OrderStatusViewModel vm = Mapper.Map <PlaceOrderViewModel, OrderStatusViewModel>(viewModel); List <OrderDet> orderDets = new List <OrderDet>(); Order ord = new Order(); ord = Mapper.Map <PlaceOrderViewModel, Order>(viewModel); ord.OrderDets = new List <OrderDet>(); vm.TotalPrice = "0"; //Xu ly concurrency for (int i = 0; i < viewModel.Carts.Count(); i++) { Product pr = Mapper.Map <ProductShoppingCart, Product>(viewModel.Carts[i]); Product pr1 = productService.GetById(viewModel.Carts[i].Id); if (productService.CheckConcurency(pr)) { int qty = viewModel.Carts[i].BuyingQuantity; viewModel.Carts[i] = Mapper.Map <Product, ProductShoppingCart>(pr1); viewModel.Carts[i].BuyingQuantity = qty; viewModel.Carts[i].TotalPrice = (viewModel.Carts[i].BuyingQuantity * double.Parse((viewModel.Carts[i].PromotionalPrice == "1" ? viewModel.Carts[i].Price : viewModel.Carts[i].PromotionalPrice).Replace(".", ""))).ToString(); ModelState.AddModelError("ConcurrencyError", "Sản phẩm " + pr1.Name + " đã bị thay đổi thông tin, vui lòng xem lại sản phẩm trước khi mua"); return(View("PlaceOrder", viewModel)); } int qty1 = viewModel.Carts[i].BuyingQuantity; if (qty1 > pr1.Quantity) { ModelState.AddModelError("QuantityError", "Đồng hồ " + pr1.Name + " không còn đủ hàng. Vui lòng chọn số lượng ít hơn."); return(View("PlaceOrder", viewModel)); } pr = productService.GetById(viewModel.Carts[i].Id); vm.TotalPrice = (pr.PromotionalPrice == 1?pr.Price * viewModel.Carts[i].BuyingQuantity:pr.PromotionalPrice * viewModel.Carts[i].BuyingQuantity).ToString(); OrderDet det = new OrderDet(); det.Quantity = viewModel.Carts[i].BuyingQuantity; det.ProductId = viewModel.Carts[i].Id; det.ProductPrice = pr.PromotionalPrice == 1 ? pr.Price : pr.PromotionalPrice; det.Order = ord; ord.OrderDets.Add(det); ord.TotalCost += det.ProductPrice * det.Quantity; } vm.TotalPrice = PriceHelper.NormalizePrice(vm.TotalPrice); orderService.AddOrder(ord); Session["Carts"] = null; return(View("OrderStatus", vm)); }
public IActionResult ReviewOrder(int?id) { if (id != null) { Order order = _context.Orders.Include(o => o.OrderDets).ThenInclude(o => o.Book).FirstOrDefault(o => o.OrderID == id); string emailsubject = "Your Order is on the way!"; string uid = User.Identity.Name; AppUser user = _context.Users.FirstOrDefault(u => u.UserName == uid); string emailrecipient = user.Email; OrderDet FirstorderDet = order.OrderDets.FirstOrDefault(); int ordDetID = FirstorderDet.OrderDetID; string emailbody = "We also recommend you checkout these titles: " + GenerateBookRecommendations(ordDetID); Utilities.SendEmail.Send_Email(emailrecipient, emailsubject, emailbody); order.OrderComplete = true; //removing the ordered books from the database List <OrderDet> DetailsforBooks = new List <OrderDet>(); DetailsforBooks = order.OrderDets.ToList(); foreach (OrderDet O in DetailsforBooks) { int intAmttoReduce = O.Quantity; Book book = O.Book; book.Inventory = book.Inventory - intAmttoReduce; _context.Update(book); _context.SaveChanges(); } _context.Update(order); _context.SaveChanges(); } Order order1 = _context.Orders.Include(o => o.OrderDets).ThenInclude(o => o.Book).FirstOrDefault(o => o.OrderID == id); OrderDet FirstorderDet1 = order1.OrderDets.FirstOrDefault(); int ordDetID1 = FirstorderDet1.OrderDetID; ViewBag.Recommendations = GenerateBookRecommendations(ordDetID1); return(View("CompleteOrder")); }
public static Order Copyto(this Order entity) { if (entity == null) { throw new InvalidOperationException("申请单无效。"); } var detEntity = entity.OrderDets.FirstOrDefault(); if (detEntity == null) { throw new InvalidOperationException("申请单详细无效。"); } var detail = new OrderDet() { IOHours = detEntity.IOHours, StartDate = detEntity.StartDate, StartTime = detEntity.StartTime, EndDate = detEntity.EndDate, EndTime = detEntity.EndTime, Audit = detEntity.Audit, Description = detEntity.Description }; var order = new Order() { OrderNo = entity.OrderNo, OrderType = entity.OrderType, ApplyUserId = entity.ApplyUserId, WorkflowId = entity.WorkflowId, NextStep = entity.NextStep, NextAudit = entity.NextAudit, CreatedTime = entity.CreatedTime, Status = entity.Status, RefOrderId = entity.RefOrderId, UserId = entity.UserId }; order.OrderDets.Add(detail); return(order); }
public void createOrder(Order order) { order.orderTime = DateTime.Now; appDBContent.Order.Add(order); var items = shopCart.listShopItems; foreach (var el in items) { var orderDet = new OrderDet() { CarID = el.car.id, orderID = order.id, price = el.car.price, }; appDBContent.OrderDetail.Add(orderDet); } appDBContent.SaveChanges(); }
public IActionResult AddToOrder(int?id) { if (id == null) { return(View("Error", new string[] { "You must specify an order to add!" })); } Order ord = _context.Orders.Find(id); if (ord == null) { return(View("Error", new string[] { "Order not found!" })); } OrderDet od = new OrderDet() { Order = ord }; ViewBag.AllBooks = GetAllBooks(); return(View("AddToOrder", od)); }
public static OrderDet ToEntity(this OrderDetModel model) { var entity = new OrderDet() { Id = model.Id, OrderId = model.Id, StartDate = model.StartDate, StartTime = model.StartTime, EndDate = model.EndDate, EndTime = model.EndTime, IOHours = model.IOHours, Description = model.Description, Audit = model.Audit, InformLeader = model.InformLeader, WorkTransfer = model.WorkTransfer, Recipient = model.Recipient }; return(entity); }
public IActionResult AddToOrder(OrderDet od, int SelectedBook) { Book book = _context.Books.Find(SelectedBook); if (book.ActiveSell == true) { return(View("AddError", new string[] { "Sorry! This book has discontinued selling." })); } od.Book = book; Order ord = _context.Orders.Where(o => o.AppUser.UserName == User.Identity.Name).Where(o => o.OrderComplete == false).First(); od.Order = ord; int bookInv = book.Inventory; if (od.Quantity > bookInv) { return(View("AddError", new string[] { "Please select less than " + bookInv.ToString() })); } if (ModelState.IsValid) { od.TotalBookPrice = od.Book.Price * od.Quantity; od.TotalBookCost = od.Book.Cost * od.Quantity; _context.OrderDets.Add(od); _context.SaveChanges(); return(RedirectToAction("ShoppingCart", new { id = od.Order.OrderID })); } ViewBag.AllBooks = GetAllBooks(); return(View("ShoppingCart", od)); }
public IActionResult AddToCart(int?id) { if (id == null) { return(NotFound()); } var book = _context.Books.Include(o => o.OrderDets).ThenInclude(o => o.Order).FirstOrDefault(o => o.BookID == id); if (book == null) { return(NotFound()); } if (book.ActiveSell == true) { return(View("AddError", new string[] { "Sorry! This book has discontinued selling." })); } //wont even let u try to order a book if there's no inventory if (book.Inventory == 0) { return(View("AddError", new string[] { "Sorry! This book is not in stock." })); } Order curorder = _context.Orders.Include(o => o.OrderDets).ThenInclude(o => o.Book).Where(o => o.AppUser.UserName == User.Identity.Name) .Where(o => o.OrderComplete == false).FirstOrDefault(); if (curorder == null) { Order ord = new Order(); string username = User.Identity.Name; AppUser user = _context.Users.FirstOrDefault(u => u.UserName == username); ord.AppUser = user; OrderDet od1 = new OrderDet(); od1.Order = ord; od1.Book = book; _context.Add(ord); _context.SaveChanges(); return(View(od1)); } foreach (OrderDet ods in curorder.OrderDets) { if (ods.Book.BookID == id) { return(View("AlreadyInCartError", new string[] { "Item is already in the cart. Proceed to shopping cart to change quantity" })); } } OrderDet od = new OrderDet(); od.Order = curorder; od.Book = book; return(View(od)); }
/// <summary> /// 修改申请信息 /// </summary> /// <returns>修改状态</returns> public bool UpdateOrder(int userId, int orderNo, UpdateOrderModel model) { using (var dbContext = new MissionskyOAEntities()) { #region 申请信息 //查询申请信息是否存在 var orderEntities = dbContext.Orders.Where(o => o.OrderNo == orderNo); var orderUsers = orderEntities.Select(o => o.UserId).ToArray(); var validateEntity = orderEntities.FirstOrDefault(); if (validateEntity == null) { Log.Error("申请记录不存在。"); throw new KeyNotFoundException("申请记录不存在。"); } var validateOrder = validateEntity.ToModel(); //model转换 var applyModel = new ApplyOrderModel() { OrderType = validateOrder.OrderType, StartDate = model.StartDate, EndDate = model.EndDate, IOHours = model.IOHours, UserIds = orderUsers, InformLeader = model.InformLeader, WorkTransfer = model.WorkTransfer, Recipient = model.Recipient }; //var orderDet = new OrderDet() //{ // StartDate = model.StartDate, // EndDate = model.EndDate, // StartTime = model.StartDate.TimeOfDay, // EndTime = model.EndDate.TimeOfDay, // Description = model.Description, // InformLeader = model.InformLeader ?? false, // WorkTransfer = model.WorkTransfer ?? false, // Recipient = model.Recipient ?? 0, // IOHours = model.IOHours //}; //validateEntity.OrderDets = new List<OrderDet>() { orderDet }; //下一步审批人 var opprover = dbContext.Users.FirstOrDefault( it => validateEntity.NextAudit.HasValue && it.Id == validateEntity.NextAudit.Value); #endregion #region 验证 var validateMsg = string.Empty; if (userId != validateOrder.ApplyUserId && (opprover != null && userId != opprover.Id)) { Log.Error("用户不能修改申请单。"); throw new InvalidOperationException("用户不能修改申请单。"); } if (DateTime.Compare(model.StartDate, DateTime.Now.AddDays(-15)) < 0) { validateMsg = "开始必须大于" + string.Format("{0:F}", DateTime.Now.AddDays(-15)); Log.Error(validateMsg); throw new InvalidOperationException(validateMsg); } if (DateTime.Compare(model.StartDate, DateTime.Now.AddDays(15)) > 0) { validateMsg = "开始必须小于" + string.Format("{0:F}", DateTime.Now.AddDays(15)); Log.Error(validateMsg); throw new InvalidOperationException(validateMsg); } if (model.StartDate >= model.EndDate) { validateMsg = "结束时间必须大于开始时间"; Log.Error(validateMsg); throw new InvalidOperationException(validateMsg); } if (validateOrder.OrderType != OrderType.Overtime && validateOrder.OrderType != 0) { TimeSpan dspWorkingDayAm = DateTime.Parse("08:30").TimeOfDay; TimeSpan dspWorkingDayPm = DateTime.Parse("18:30:59").TimeOfDay; if (model.StartDate.TimeOfDay < dspWorkingDayAm) { throw new InvalidOperationException("开始时间必须大于等于上午8点半"); } if (model.EndDate.TimeOfDay > dspWorkingDayPm) { throw new InvalidOperationException("结束时间必须小于等于下午6点半"); } } else { TimeSpan dspWorkingDayAm = DateTime.Parse("08:30").TimeOfDay; if (model.StartDate.TimeOfDay < dspWorkingDayAm) { throw new InvalidOperationException("开始时间必须大于上午8点半"); } } var invalidUsers = IsOrderTimeAvailiable(applyModel, orderNo); if (!string.IsNullOrEmpty(invalidUsers)) { throw new InvalidOperationException(string.Format("用户({0})此申请时段已经占用。", invalidUsers)); } #endregion #region 更新信息 var existedUser = new List <int>(); //申请单原本已经有的用户 if ((int)OrderStatus.Apply == validateEntity.Status || (opprover != null && opprover.ToModel().IsAdminStaff)) { #region 更新已存在的用户申请 orderEntities.ToList().ForEach(o => { if (model.UserIds.Contains(o.UserId)) //更新用户申请单 { OrderDet detailEntity = null; if (o.OrderDets == null || o.OrderDets.Any() == false) { detailEntity = dbContext.OrderDets.FirstOrDefault(od => od.OrderId == o.Id); } else { detailEntity = o.OrderDets.FirstOrDefault(); } //o.OrderType = (int)model.OrderType; 不能更新申请单类型 if (detailEntity != null) { detailEntity.StartDate = model.StartDate.Date; detailEntity.EndDate = model.EndDate.Date; detailEntity.IOHours = model.IOHours; detailEntity.StartTime = model.StartDate.TimeOfDay; detailEntity.EndTime = model.EndDate.TimeOfDay; detailEntity.Description = model.Description; detailEntity.InformLeader = model.InformLeader ?? detailEntity.InformLeader; detailEntity.WorkTransfer = model.WorkTransfer ?? detailEntity.WorkTransfer; detailEntity.Recipient = model.Recipient ?? detailEntity.Recipient; } existedUser.Add(o.UserId); //申请单原本已经有的用户 } else //移除用户申请单 { o.OrderDets.ToList().ForEach(d => dbContext.OrderDets.Remove(d)); //移出申请单详细 dbContext.Orders.Remove(o); //移出申请单 //o.Status = (int) OrderStatus.Canceled; //o.NextAudit = 0; //o.NextStep = 0; } }); #endregion #region 添加新增用户申请 model.UserIds.ToList().ForEach(it => { //validateOrder if (!existedUser.Contains(it)) { var newOrder = validateEntity.Copyto(); newOrder.UserId = it; //如果是修改撤销单 if (validateEntity.RefOrderId.HasValue) { var refOrder = GetOrderDetail(dbContext, validateEntity.RefOrderId.Value, false); if (refOrder != null) { newOrder.RefOrderId = _orderService.GetOrderIdByOrderNoAndUserId(dbContext, refOrder.OrderNo, it); } } dbContext.Orders.Add(newOrder); } }); #endregion //发送工作交接通知 if (model.WorkTransfer.HasValue && model.WorkTransfer.Value && model.Recipient.HasValue && validateEntity.OrderType != (int)OrderType.Overtime) { _orderService.AddNotification(dbContext, validateEntity.ToModel()); } dbContext.SaveChanges(); return(true); } else { Log.Error("已处于审批流程,不能更新。"); throw new InvalidOperationException("已处于审批流程,不能更新"); } #endregion } }
private String GenerateBookRecommendations(int?id) { List <Book> BooksToRec = new List <Book>(); OrderDet od = _context.OrderDets.Include(o => o.Book.Genre).FirstOrDefault(o => o.OrderDetID == id); Book OrderedBook = od.Book; Genre OrderedGenre = OrderedBook.Genre; var old_orderDetails = _context.OrderDets.Where(m => m.Order.OrderComplete == true) .Where(o => o.Order.AppUser.UserName == User.Identity.Name).Include(m => m.Book).ToList(); List <Book> DoNotRec = new List <Book>(); foreach (OrderDet ord in old_orderDetails) { DoNotRec.Add(ord.Book); } var BooksSameGenreAuthor = _context.Books.Where(b => b.Genre == OrderedBook.Genre) .Where(b => b.Author == OrderedBook.Author).ToList(); var maxValue = BooksSameGenreAuthor.Max(x => x.AvgRating); Book HighestRated = BooksSameGenreAuthor.First(x => x.AvgRating == maxValue); if (DoNotRec.Contains(HighestRated) == false) { BooksToRec.Add(HighestRated); } var BooksSameGenre = _context.Books.Where(b => b.Genre == OrderedBook.Genre) .Where(b => b.Author != OrderedBook.Author).ToList(); var maxValue2 = BooksSameGenre.Max(x => x.AvgRating); Book HighestRated2 = BooksSameGenre.First(x => x.AvgRating == maxValue2); if ((HighestRated2.AvgRating >= 4) && (DoNotRec.Contains(HighestRated2) == false)) { BooksToRec.Add(HighestRated2); BooksSameGenre.Remove(HighestRated2); DoNotRec.Add(HighestRated2); } var maxValue3 = BooksSameGenre.Max(x => x.AvgRating); Book HighRated3 = BooksSameGenre.First(x => x.AvgRating == maxValue3); if ((HighRated3.AvgRating >= 4) && (DoNotRec.Contains(HighRated3) == false) && (HighestRated2.Author != HighRated3.Author)) { BooksToRec.Add(HighRated3); BooksSameGenre.Remove(HighRated3); DoNotRec.Add(HighRated3); } if (BooksToRec.Count() == 3) { string final_recs = ""; foreach (Book b in BooksToRec) { final_recs = final_recs + b.Title.ToString() + " "; } return(final_recs); } BooksSameGenre = BooksSameGenre.Where(x => x.AvgRating >= 4).ToList(); foreach (Book b in BooksSameGenre) { if (DoNotRec.Contains(b) == false) { BooksToRec.Add(b); DoNotRec.Add(b); if (BooksToRec.Count() == 3) { string final_recs = ""; foreach (Book bb in BooksToRec) { final_recs = final_recs + bb.Title.ToString() + " "; } return(final_recs); } } } var GenreBooks = _context.Books.Where(b => b.Genre == OrderedBook.Genre).ToList(); foreach (Book b in GenreBooks) { if (DoNotRec.Contains(b) == false) { BooksToRec.Add(b); DoNotRec.Add(b); if (BooksToRec.Count() == 3) { string final_recs = ""; foreach (Book bb in BooksToRec) { final_recs = final_recs + bb.Title.ToString() + " "; } return(final_recs); } } } List <Book> books = _context.Books.ToList(); while (BooksToRec.Count() < 3) { var maxRate = books.Max(x => x.AvgRating); Book b = books.First(x => x.AvgRating == maxRate); books.Remove(b); if (DoNotRec.Contains(b) == false) { BooksToRec.Add(b); DoNotRec.Add(b); if (BooksToRec.Count() == 3) { string final_recs = ""; foreach (Book bb in BooksToRec) { final_recs = final_recs + bb.Title.ToString() + " "; } return(final_recs); } } } string recs = ""; foreach (Book bb in BooksToRec) { recs = recs + bb.Title.ToString() + "\n"; } return(recs); ////list of books that'll be passed back //List<Book> BooksToRec = new List<Book>(); ////order details of existing order //OrderDet od = _context.OrderDets.Include(o => o.Book.Genre).FirstOrDefault(o => o.OrderDetID == id); //string Author = od.Book.Author; ////List to find old order details //var old_orderDetails = _context.OrderDets.Where(m => m.Order.OrderComplete == true).Where(o => o.Order.AppUser.UserName == User.Identity.Name).Include(m => m.Book).ToList(); //List<OrderDet> old_ods = old_orderDetails; //List<Book> PrevBoughtBooks = new List<Book>(); //List<Book> BookswithSameAuthor = new List<Book>(); //var sameAuthor = _context.Books.Where(b => b.Author == Author).ToList(); //BookswithSameAuthor = sameAuthor; //foreach (OrderDet old_od in old_ods) //{ // Book tempbook = old_od.Book; // PrevBoughtBooks.Add(tempbook); //} ////distinct previously bought books //List<Book> prevDistinctBooks = PrevBoughtBooks.Distinct().ToList(); ////Adding books with Same Author & Genre //while (BooksToRec.Count() < 3) //{ // Genre genre = od.Book.Genre; // string genrename = genre.GenreName.ToString(); // var books = _context.Books.Where(o => o.Genre.GenreName == genrename).ToList(); // List<Book> authorbookstorate = new List<Book>(); // foreach (Book bok in BookswithSameAuthor) // { // if (books.Contains(bok)) // { // authorbookstorate.Add(bok); // } // } // List<Book> ratedbooks = new List<Book>(); // var query = from b in authorbookstorate // select b; // query = query.OrderByDescending(b => b.AvgRating); // ratedbooks = ratedbooks.ToList(); // foreach (Book book1 in ratedbooks) // { // if (!prevDistinctBooks.Contains(book1)) // { // if (!BooksToRec.Contains(book1)) // { // BooksToRec.Add(book1); // } // } // } //} ////if top list isn't filled find books of same genre with different authors where rating > 4 //while (BooksToRec.Count() < 3) //{ // Genre genre = od.Book.Genre; // string genrename = genre.GenreName.ToString(); // var books = _context.Books.Where(o => o.Genre.GenreName == genrename).ToList(); // foreach (Book b in books) // { // List<String> Authors = new List<string>(); // Authors.Add(b.Author); // List<String> usedAuthors = new List<string>(); // foreach (var a in Authors) // { // if (b.Author == a) // { // if (!prevDistinctBooks.Contains(b)) // { // if (!usedAuthors.Contains(a)) // { // if (!BooksToRec.Contains(b)) // { // if (b.AvgRating >= 4) // { // BooksToRec.Add(b); // usedAuthors.Add(a); // } // } // } // } // } // } // } //} ////if list isn't filled yet, add whatever is left in the genre //while (BooksToRec.Count() < 3) //{ // string genre = od.Book.Genre.GenreName; // var books = _context.Books.Where(o => o.Genre.GenreName == genre).ToList(); // foreach (Book b in books) // { // if (!prevDistinctBooks.Contains(b)) // { // if (!BooksToRec.Contains(b)) // { // BooksToRec.Add(b); // } // } // } //} ////if list isn't filled yet, just add highest rated books //if (BooksToRec.Count() < 3) //{ // List<Book> unorderedRemainingBooks = new List<Book>(); // List<Book> orderedRemainingBooks = new List<Book>(); // var books = _context.Books.ToList(); // unorderedRemainingBooks = books; // var query = from b in unorderedRemainingBooks // select b; // query = query.OrderByDescending(b => b.AvgRating); // orderedRemainingBooks = query.ToList(); // while (BooksToRec.Count() <= 3) // { // foreach (Book bok in orderedRemainingBooks) // { // if (!prevDistinctBooks.Contains(bok)) // { // if (!BooksToRec.Contains(bok)) // { // BooksToRec.Add(bok); // } // } // } // } //} //string final_recs = ""; //foreach (Book b in BooksToRec) //{ // final_recs = final_recs + b.Title.ToString() + " "; //} //return final_recs; }
public async Task <IActionResult> Edit(int id, int SelectedGenre, [Bind("BookID,Title,Author,PublishDate,Description,Inventory,ReorderLevel,Cost,Price,ActiveSell")] Book book) { if (id != book.BookID) { return(NotFound()); } if (ModelState.IsValid) { try { Book dbBook = await _db.Books .Include(g => g.Genre) .FirstOrDefaultAsync(b => b.BookID == book.BookID); if (dbBook.ActiveSell == false && book.ActiveSell == true) { List <AppUser> UsersWithBookInCart = new List <AppUser>(); List <AppUser> Customers = _db.Users.Include(u => u.Orders).Where(o => o.Orders.Count() > 0).ToList(); foreach (AppUser cust in Customers) { Boolean bolUserHas = false; List <Order> orders = _db.Orders.Include(o => o.AppUser).Where(u => u.AppUser.UserName == cust.UserName).ToList(); foreach (Order ord in orders.Where(r => r.OrderComplete == false)) { List <OrderDet> ods = _db.OrderDets.Include(b => b.Book).ToList(); foreach (OrderDet od in ods) { if (od.Book.BookID == book.BookID) { bolUserHas = true; } } } if (bolUserHas == true) { UsersWithBookInCart.Add(cust); } } foreach (AppUser us in UsersWithBookInCart) { string subjectline = "Discontinued Book"; string body = "One of the books in your shopping cart has been discontinued. Your shopping cart has been updated."; Utilities.SendEmail.Send_Email(us.Email, subjectline, body); List <Order> orders = _db.Orders.Include(o => o.AppUser).Where(u => u.AppUser.UserName == us.UserName).ToList(); foreach (Order ord in orders.Where(r => r.OrderComplete == false)) { List <OrderDet> ods = _db.OrderDets.Include(b => b.Book).ToList(); foreach (OrderDet od in ods) { if (od.Book.BookID == book.BookID) { OrderDet ood = _db.OrderDets.FirstOrDefault(p => p.OrderDetID == od.OrderDetID); _db.Remove(ood); _db.SaveChanges(); } } } } } dbBook.BookID = book.BookID; dbBook.Title = book.Title; dbBook.Author = book.Author; dbBook.PublishDate = book.PublishDate; dbBook.Description = book.Description; dbBook.Inventory = book.Inventory; dbBook.ReorderLevel = book.ReorderLevel; dbBook.Cost = book.Cost; dbBook.Price = book.Price; dbBook.ActiveSell = book.ActiveSell; dbBook.Genre = _db.Genres.Find(SelectedGenre); _db.Update(dbBook); _db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(book.BookID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewBag.AllGenres = GetAllGenresMustSelectOne(); return(View(book)); }
public bool Update(OrderDet obj) { throw new NotImplementedException(); }
public OrderDet Delete(OrderDet obj) { throw new NotImplementedException(); }