public JsonResult 實體店新增訂單(EmployeeOrderViewModel empOrder)
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         tEmployee emp = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
         if (Session[CSession關鍵字.SK_ORDERDETAIL] == null)
         {
             return(Json(new { result = false, msg = "訂單尚未完成!", url = Url.Action("實體店新增訂單", "Order") }));
         }
         else
         {
             List <EmployeeOrderDetailViewModel> orders = Session[CSession關鍵字.SK_ORDERDETAIL] as List <EmployeeOrderDetailViewModel>;
             MotaiDataEntities dbContext = new MotaiDataEntities();
             tCustomer         customer  = dbContext.tCustomers.Where(c => c.cCellPhone == empOrder.cCellphone).FirstOrDefault();
             tOrder            list      = new tOrder();
             list.oEmployeeId = emp.EmployeeId;
             list.oCustomerId = customer.CustomerId;
             if (empOrder.oAddress == null)
             {
                 list.oAddress = customer.cAddress;
             }
             else
             {
                 list.oAddress = empOrder.oAddress;
             }
             list.oDate          = empOrder.oDate;
             list.cNote          = empOrder.cNote;
             list.oWarehouseName = empOrder.oWarehouseName;
             dbContext.tOrders.Add(list);
             dbContext.SaveChanges();
             int orderId       = dbContext.tOrders.OrderByDescending(i => i.OrderId).First().OrderId;
             int originalPrice = 0;
             foreach (var items in orders)
             {
                 tOrderDetail detail = new tOrderDetail();
                 detail.oOrderId    = orderId;
                 detail.oProductId  = items.oProductId;
                 detail.oProductQty = items.oProductQty;
                 detail.oNote       = items.oNote;
                 dbContext.tOrderDetails.Add(detail);
                 tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(items.oProductId)).FirstOrDefault();
                 originalPrice += items.oProductQty * Convert.ToInt32(product.pPrice);
             }
             tOrder order       = dbContext.tOrders.Where(o => o.OrderId == orderId).FirstOrDefault();
             int    promotionId = orderRespoitory.SelectPromotionId(originalPrice, empOrder.oDate);
             if (promotionId != 0)
             {
                 order.oPromotionId = promotionId;
             }
             dbContext.SaveChanges();
             Session[CSession關鍵字.SK_ORDERDETAIL] = null;
             return(Json(new { result = true, msg = "新增成功", url = Url.Action("realCheckView", "Order"), OrderId = orderId }));
         }
     }
     else
     {
         return(Json(new { result = false, msg = "尚未登入!", url = Url.Action("員工登入", "Employee") }));
     }
 }
Beispiel #2
0
 public ActionResult 實體店新增訂單()
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         tEmployee emp = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
         EmployeeOrderViewModel model = new EmployeeOrderViewModel();
         model.oEmployeeId = emp.EmployeeId;
         var warehouseNames = commodityRespoitory.GetWarehouseAll();
         List <SelectListItem> warehouselist = commodityRespoitory.GetSelectList(warehouseNames);
         model.WareHouseNames = warehouselist;
         return(View(model));
     }
     else
     {
         return(RedirectToAction("員工登入", "Employee"));
     }
 }
Beispiel #3
0
        public HttpResponseMessage AddOrdersToEmployee(HttpRequestMessage request, JObject objData)
        {
            //**** SOURCE URL SAMPLE:  http://www.dotnetcurry.com/aspnet/1278/aspnet-webapi-pass-multiple-parameters-action-method
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                      .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    dynamic jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject(objData.ToString());
                    var employeeIdJson = jsonData.jsonObj.employeeId;
                    var ordersJson = jsonData.jsonObj.orders;

                    List <EmployeeOrder> EmployeeOrderobj = new List <EmployeeOrder>();

                    foreach (var orderid in ordersJson)
                    {
                        EmployeeOrderViewModel employeeorderVM = new EmployeeOrderViewModel();
                        EmployeeOrder newemployeeorder = new EmployeeOrder();
                        newemployeeorder.OrderId = orderid.Id;
                        newemployeeorder.CommissionedEmployeeId = employeeIdJson;
                        _employeeordersRepository.Add(newemployeeorder);
                        _unitOfWork.Commit();

                        EmployeeOrderobj.Add(newemployeeorder);
                    }
                    IEnumerable <EmployeeOrderViewModel> EmployeeordersVM = Mapper.Map <IEnumerable <EmployeeOrder>, IEnumerable <EmployeeOrderViewModel> >(EmployeeOrderobj);
                    response = request.CreateResponse <IEnumerable <EmployeeOrderViewModel> >(HttpStatusCode.OK, EmployeeordersVM);
                }
                return response;
            }));
        }
 public ActionResult 實體店新增訂單()
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         tEmployee emp = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
         EmployeeOrderViewModel       model  = new EmployeeOrderViewModel();
         EmployeeOrderDetailViewModel detail = new EmployeeOrderDetailViewModel();
         model.oEmployeeId = emp.EmployeeId;
         var warehouseNames = commodityRespoitory.GetWarehouseAll();
         List <SelectListItem> warehouselist = commodityRespoitory.GetSelectList(warehouseNames);
         var productNames = productRespoitory.GetNameAll();
         List <SelectListItem> productlist = commodityRespoitory.GetSelectList(productNames);
         model.WareHouseNames = warehouselist;
         detail.ProductNames  = productlist;
         detail.oProductQty   = 1;
         model.oDate          = DateTime.Now.Date;
         model.empOrderDetail = detail;
         return(View(model));
     }
     else
     {
         return(RedirectToAction("員工登入", "Employee"));
     }
 }
        //實體結帳畫面
        public ActionResult realCheckView(int OrderId)
        {
            MotaiDataEntities         dbContext = new MotaiDataEntities();
            EmployeeCheckoutViewModel model     = new EmployeeCheckoutViewModel();
            EmployeeOrderViewModel    Order     = new EmployeeOrderViewModel();
            tOrder order = dbContext.tOrders.Where(o => o.OrderId.Equals(OrderId)).FirstOrDefault();

            Order.CustomerName = dbContext.tCustomers.Where(c => c.CustomerId == order.oCustomerId).FirstOrDefault().cName;
            Order.oAddress     = order.oAddress;
            Order.oDate        = order.oDate;
            if (order.cNote != null)
            {
                Order.cNote = order.cNote;
            }
            else
            {
                Order.cNote = "無";
            }

            List <tOrderDetail> orderDetails = dbContext.tOrderDetails.Where(od => od.oOrderId.Equals(OrderId)).ToList();
            List <EmployeeOrderDetailViewModel> Orderdetails = new List <EmployeeOrderDetailViewModel>();

            foreach (var itemdetails in orderDetails)
            {
                tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(itemdetails.oProductId)).FirstOrDefault();
                EmployeeOrderDetailViewModel Orderdetail = new EmployeeOrderDetailViewModel();
                Orderdetail.oOrderId     = OrderId;
                Orderdetail.ProductName  = product.pName;
                Orderdetail.ProductNum   = product.pNumber;
                Orderdetail.ProductPrice = product.pPrice;
                Orderdetail.oProductQty  = itemdetails.oProductQty;
                model.originalPrice     += itemdetails.oProductQty * Convert.ToInt32(product.pPrice);
                Orderdetails.Add(Orderdetail);
            }
            if (order.oPromotionId != null)
            {
                tPromotion promotion = dbContext.tPromotions.Where(p => p.PromotionId == order.oPromotionId).FirstOrDefault();
                Order.PromotionName      = promotion.PromotionName;
                Order.PromotionDiscount  = promotion.pDiscount;
                Order.PromotionCondition = promotion.pCondition;
                model.TotalAmount        = model.originalPrice - Convert.ToInt32(promotion.pDiscount);
            }
            else
            {
                Order.PromotionName      = "不適用任何優惠活動";
                Order.PromotionDiscount  = "0";
                Order.PromotionCondition = "無";
                model.TotalAmount        = model.originalPrice;
            }
            model.AlreadyPay = 0;
            model.Unpaid     = model.TotalAmount;
            if (dbContext.tOrderPays.Where(op => op.oOrderId.Equals(OrderId)).ToList() != null)
            {
                List <tOrderPay> pays = dbContext.tOrderPays.Where(op => op.oOrderId.Equals(OrderId)).ToList();
                foreach (var item in pays)
                {
                    model.AlreadyPay += Convert.ToInt32(item.oPayment);
                }
                model.Unpaid = model.TotalAmount - model.AlreadyPay;
            }
            model.Order        = Order;
            model.orderDetails = Orderdetails;

            return(View(model));
        }
Beispiel #6
0
 public JsonResult 實體店新增訂單(EmployeeOrderViewModel empOrder)
 {
     return(Json(new { }));
 }