private async Task CreateProductOrder(Guid customerId, OrderProductDetail orderProductDetail) { await _sqlService.CreateOrder(orderProductDetail.Code, customerId, orderProductDetail.Quantity); await _sqlService.UpdateProductQuantity(orderProductDetail.Code, orderProductDetail.Quantity); // Only for the demo product check if we need to switch the video if (orderProductDetail.Code == Constants.DemoProductId) { try { var deviceState = await _ioTCentralService.GetDeviceState(); var videoPathDesiredValue = deviceState.Manage.Metadata.VideoPath.DesiredValue; if (string.Equals(videoPathDesiredValue, Constants.StockedShelf, StringComparison.OrdinalIgnoreCase)) { await _ioTCentralService.SetVideoPathProperty(Constants.LowStockedShelf); } } catch (Exception e) { throw new Exception($"Can't update desired property: {e.Message}"); } } }
/// <summary> /// 获取产品详情 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <OrderProductDetail> GetHaveProduct(EntityDto <int> input) { var order = await _ordeRepository.FirstOrDefaultAsync(input.Id); if (order == null) { throw new UserFriendlyException("该订单不存在"); } var dto = new OrderProductDetail() { Id = order.Id, Cate = order.LevelTwo, Count = order.Count, FormId = order.FormId, Price = order.Price, ProductName = order.ProductName, TotalPrice = order.TotalPrice, OrderNum = order.OrderNum, CreationTime = order.CreationTime, State = order.State, ProductId = order.ProductId }; if (order.Profile.HasValue) { dto.Profile = Host + (await _objectManager.GetOrNullAsync(order.Profile.Value))?.Url; } return(dto); }
public ActionResult DeleteConfirmed(int id) { OrderProductDetail orderProductDetail = db.OrderProductDetail.Find(id); db.OrderProductDetail.Remove(orderProductDetail); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "OrderProductDetailID,OrerProductID")] OrderProductDetail orderProductDetail) { if (ModelState.IsValid) { db.Entry(orderProductDetail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orderProductDetail)); }
public ActionResult Create([Bind(Include = "OrderProductDetailID,OrerProductID")] OrderProductDetail orderProductDetail) { if (ModelState.IsValid) { db.OrderProductDetail.Add(orderProductDetail); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orderProductDetail)); }
// GET: OrderProductDetails/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OrderProductDetail orderProductDetail = db.OrderProductDetail.Find(id); if (orderProductDetail == null) { return(HttpNotFound()); } return(View(orderProductDetail)); }
/// <summary> /// 获取所有产品列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <PagedResultDto <OrderProductDetail> > GetHaveProducts(GetHaveProductInput input) { var query = _ordeRepository.GetAll().Where(c => c.CustomerId == input.CustomerId); var chargeRecordCount = await query.CountAsync(); var chargeRecords = await query .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); var output = new List <OrderProductDetail>(); if (chargeRecordCount <= 0) { return(new PagedResultDto <OrderProductDetail>(0, output)); } var products = await _productRepository.GetAllListAsync(); foreach (var o in chargeRecords) { var p = products.FirstOrDefault(c => o.ProductId == c.Id); var dto = new OrderProductDetail() { Id = o.Id, Cate = o.LevelTwo, Count = o.Count, CustomerName = o.Form?.CompanyName, FormId = o.FormId, Price = o.Price, ProductName = o.ProductName, TotalPrice = o.TotalPrice, OrderNum = o.OrderNum, CreationTime = o.CreationTime, State = o.State, ProductId = o.ProductId, RequireForm = p?.RequireForm }; if (o.Profile.HasValue) { dto.Profile = Host + (await _objectManager.GetOrNullAsync(o.Profile.Value))?.Url; } output.Add(dto); } return(new PagedResultDto <OrderProductDetail>( chargeRecordCount, output )); }