public IActionResult Delete(int pid, int id) { var productOD = productOrderDetailRepository.Get(id); var orderDetail = orderDetailRepository.Get(productOD.OrderDetailId); var delPOD = productOrderDetailRepository.Delete(id); var delOD = orderDetailRepository.Delete(orderDetail.OrderDetailId); if (delOD && delPOD) { var orderDetailCheck = (from od in orderDetailRepository.Gets() where od.OrderId == pid && od.Paid == false select od).FirstOrDefault(); if (orderDetailCheck != null) { var url = "https://localhost:44366/Home/Index/" + orderDetail.OrderId; return(Redirect(url)); } else { var order = orderRepository.Get(pid); order.Using = false; var result = orderRepository.Edit(order); if (result != null) { var url = "https://localhost:44366/Home/Index/" + orderDetail.OrderId; return(Redirect(url)); } } } return(View()); }
public void DeleteDetail(int productId, int orderId, int colorId, int sizeId) { var detail = _orderDetailRepository.GetSingleByCondition(x => x.ProductID == productId && x.OrderID == orderId && x.ColorId == colorId && x.SizeId == sizeId); _orderDetailRepository.Delete(detail); }
public async Task <List <OrderDetailDTO> > DeleteOrderDetailAsync(List <OrderDetailDTO> orderDetailsFromView, int orderId) { List <OrderDetail> orderDetailsFromDB = await _orderDetailRepository.Query(x => x.OrderId == orderId, false).SelectAsync(); List <OrderDetailDTO> deletedItems = new List <OrderDetailDTO>(); bool delete; foreach (var item1 in orderDetailsFromDB) { delete = true; foreach (var item2 in orderDetailsFromView) { if ((item2.Id != 0) && (item1.Id == item2.Id)) { delete = false; } } if (delete) { _orderDetailRepository.Delete(item1); deletedItems.Add(Mapper.Map <OrderDetailDTO>(item1)); } } return(deletedItems); }
public ActionResult DeleteConfirmed(int id) { orderdetailRepository.Delete(id); orderdetailRepository.Save(); return(RedirectToAction("Index")); }
public void UpdateOrder(Order order) { var newDetail = order.OrderDetail; var oldDetails = _orderDetailRepository.GetMany(x => x.OrderId == order.Id); foreach (var old in oldDetails) { _orderDetailRepository.Delete(old); _unitOfWork.Commit(); } foreach (var detail in newDetail) { CreateOrderDetail(detail); } _orderRepository.Update(order); order.Total = newDetail.Sum(x => x.Price * x.Quantity); SaveOrder(); }
public bool Delete(int orderId, int productId) { var detail = OrderDetailRepository.Get(orderId, productId); if (detail == null) { throw new NotFoundEntityException($"Order detail with orderId: {orderId}, productId: {productId}"); } return(OrderDetailRepository.Delete(orderId, productId)); }
// DELETE api/Customer/5 public HttpResponseMessage DeleteOrderDetail(int Id) { Order_Detail orderDetail = _orderDetailRepository.Get().FirstOrDefault(e => e.OrderID == Id); if (orderDetail == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } _orderDetailRepository.Delete(orderDetail); try { _unitOfWork.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, orderDetail)); }
public IActionResult DeleteOrderDetail(int orderDetailId) { var orderDetail = _orderDetailRepository.GetById(orderDetailId); var orderId = orderDetail.OrderId; _orderDetailRepository.Delete(orderDetailId); //update order var order = _orderRepository.GetById(orderDetail.OrderId); order.IsSpecialPromo = _promotionRepository.CheckPromotionBuy1Get1(); _orderRepository.Edit(order); return(new RedirectResult(Url.Action("Edit", new { orderId = orderDetail.OrderId }) + "#editdrinks")); }
public void Delete(int id) { var order = GetById(id); var orderIsDeleted = OrderRepository.Delete(id); var detailsIsDeleted = OrderDetailRepository.Delete(id); //it can be? if (!orderIsDeleted) { throw new EntityNotDeletedException($"The order with {id} not deleted."); } if (detailsIsDeleted != order.OrderDetails.Count) { throw new EntityNotDeletedException($"Detals for order id: {id} not deleted."); } }
public BaseViewModel <IEnumerable <OrderDetailViewModel> > UpdateDetail(Guid id, IEnumerable <CreateOrderDetailViewModel> details) { var result = new BaseViewModel <IEnumerable <OrderDetailViewModel> >(); if (details != null) { var listDetail = _orderDetaiRrepository.GetAll().Where(x => x.OrderId == id); foreach (var detail in listDetail) { _orderDetaiRrepository.Delete(detail); } var entities = _mapper.Map <IEnumerable <OrderDetail> >(details); foreach (var entity in entities) { entity.Id = Guid.NewGuid(); entity.SetDefaultInsertValue(_orderDetaiRrepository.GetUsername()); _orderDetaiRrepository.Add(entity); } if (entities == null) { return(new BaseViewModel <IEnumerable <OrderDetailViewModel> >() { Description = MessageHandler.CustomMessage(MessageConstants.NO_RECORD), Code = MessageConstants.NO_RECORD }); } result = new BaseViewModel <IEnumerable <OrderDetailViewModel> > { Data = _mapper.Map <IEnumerable <OrderDetailViewModel> >(entities), }; } Save(); return(result); }
public bool Delete(int OrderDetailId, out string message) { try { var entity = _OrderDetailRepository.GetById(OrderDetailId); if (entity != null) { _OrderDetailRepository.Delete(OrderDetailId); UnitOfwork.SaveChanges(); message = Constants.DeleteSuccess; return(true); } message = Constants.DeleteFail; return(false); } catch { message = Constants.RecordsisUsedCanNotDeleted; return(false); } }
public ActionResult DeleteOrderDetail(OrderDetailDelModel req) { if (ModelState.IsValid) { if (_orderRepository.CheckStatusOrder(req.OrderId) == 0) { if (_orderDetailRepository.CheckOrderDetailBelongToOrder(req.OrderDetailId, req.OrderId) == 1) { Order order = _orderRepository.Get(req.OrderId); if (order.UserId.Equals(req.UserId)) { OrderDetail orderDetail = _orderDetailRepository.Get(req.OrderDetailId); if (orderDetail != null) { _orderDetailRepository.Delete(req.OrderDetailId); if (_orderDetailRepository.SaveChanges() == 1) { int price = -(req.Quantity * req.UnitPrice); int result = UpdateOrderAfterBuy(req.OrderId, price); if (result != -1) { return(Ok(JsonConvert.SerializeObject(new { totalPrice = result }))); } } return(BadRequest(JsonConvert.SerializeObject(new { message = "Server Error." }))); } return(BadRequest(JsonConvert.SerializeObject(new { message = "The order detail is not found." }))); } return(BadRequest(JsonConvert.SerializeObject(new { message = "The order is not macth to user." }))); } return(BadRequest(JsonConvert.SerializeObject(new { message = "Order detail is not match to order." }))); } return(BadRequest(JsonConvert.SerializeObject(new { message = "The cart is done." }))); } return(BadRequest(ModelState)); }
public OrderDetail Delete(int id) { return(_OrderDetailRepository.Delete(id)); }
public OrderDetail Delete(Guid id) { return(_orderDetailRepository.Delete(id)); }
public void Delete(int id) { _orderDetailRepository.Delete(id); }
public void Delete(OrderDetail entity) { _OrderDetailRepository.Delete(entity); }
public OrderDetail Delete(int id) { return(_orderDetail.Delete(id)); }