Exemple #1
0
        public JsonResult SerializeFormDataForEdit(int OrderID, FormCollection _collection)
        {
            Order order = orderService.FindById(OrderID);

            if (order == null)
            {
                return(Json(new { Success = false, Message = "This OrderID not found" }, JsonRequestBehavior.AllowGet));
            }
            if (_collection != null)
            {
                string[] _productID, _DemandQty, _ActualQty, _price, _amt, _flag, _detailId;
                //for orderDetails
                _productID = _collection["ProductID"].Split(',');
                _DemandQty = _collection["DemandQty"].Split(',');
                _ActualQty = _collection["ActualQty"].Split(',');
                _price     = _collection["Price"].Split(',');
                _amt       = _collection["Amount"].Split(',');
                _flag      = _collection["Flag"].Split(',');
                _detailId  = _collection["DetailId"].Split(',');
                //for order
                DateTime requireDate = Convert.ToDateTime(_collection["RequireDate"]);

                decimal _total        = Convert.ToDecimal(_collection["Total"]);
                int     DistributorID = Convert.ToInt32(_collection["DistributorID"]);
                //decimal _discount = Convert.ToDecimal(_collection["Discount"]);
                //decimal _grandTotal = Convert.ToDecimal(_collection["GrandTotal"]);
                DateTime _date = DateTime.Now;

                order.RequireDeliveryDate = requireDate;
                order.ToTalAmount         = _total;
                order.EmployeeId          = Convert.ToInt32(Session["EmployeeId"]);
                //order.Update_At = DateTime.Now;
                int success = 0;
                //success = orderService.Edit(order);

                if (success > 0)
                {
                    //service.UpdateStock(_stockID, _qty);
                    if ((detailService.AddOrEditListDetail(order.OrderId, _detailId, _productID, _price, _DemandQty, _ActualQty, _flag)) == _productID.Count())
                    {
                        //Invoice invoice = new Invoice()
                        //{
                        //    OrderId = orderID,
                        //    Amount = _total,
                        //    EmployeeId = Convert.ToInt32(Session["EmployeeId"])
                        //};
                        return(Json(new { success = true, message = "Order added" }, JsonRequestBehavior.AllowGet));
                    }

                    return(Json(new { success = false, message = "wrong with insert detail" }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { success = false, message = "wrong with generic Order" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { success = false, message = "wrong from form" }, JsonRequestBehavior.AllowGet));
        }