public JsonResult SaveNewRequest(CustRequest Model)
 {
     if (string.IsNullOrEmpty(Model.OrderID))
     {
         var OrderData = objCustRequest.SaveOrderRequest(Model);
         return(new JsonResult {
             Data = OrderData, JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
     else
     {
         if (Model.Type.Equals("1"))
         {
             var OrderData = objCustRequest.SaveOrderRequest(Model);
             return(new JsonResult {
                 Data = OrderData, JsonRequestBehavior = JsonRequestBehavior.AllowGet
             });
         }
         else
         {
             var OrderData = objCustOrderData.SaveOrderRequest(Model);
             return(new JsonResult {
                 Data = OrderData, JsonRequestBehavior = JsonRequestBehavior.AllowGet
             });
         }
     }
 }
        public List <dynamic> SaveOrderRequest(CustRequest custreq)
        {
            var           OrderIDdet    = new List <dynamic>();
            SaveTempOrder SaveTempOrder = new SaveTempOrder();
            Order         ord           = new Order();

            if (!string.IsNullOrEmpty(custreq.OrderID))
            {
                ord.OrderId = Convert.ToInt64(securityHelper.Decrypt(custreq.OrderID, false));
            }
            else
            {
                ord.OrderId = 0;
            }


            if (!string.IsNullOrEmpty(custreq.BranchID))
            {
                ord.BranchId = Convert.ToInt64(custreq.BranchID);
            }
            else
            {
                ord.BranchId = 0;
            }
            if (!string.IsNullOrEmpty(custreq.SCity))
            {
                ord.CityId = Convert.ToInt64(custreq.SCity);
                //ord.CityId = 1;
            }
            else
            {
                ord.CityId = 0;
            }

            if (!string.IsNullOrEmpty(custreq.SCountry))
            {
                ord.CountryId = Convert.ToInt64(custreq.SCountry);
                //ord.CountryId = 1;
            }
            else
            {
                ord.CountryId = 0;
            }
            if (!string.IsNullOrEmpty(custreq.selectedCustomer))
            {
                ord.CustId = Convert.ToInt64(custreq.selectedCustomer);
            }
            else
            {
                ord.CustId = 0;
            }

            ord.Department = custreq.Department;
            if (!string.IsNullOrEmpty(custreq.DeliveryTo))
            {
                ord.IncoTermId = Convert.ToInt64(custreq.DeliveryTo);
            }
            else
            {
                ord.IncoTermId = 0;
            }
            ord.ContactName  = custreq.Sname;
            ord.ContactEmail = custreq.Semail;
            ord.ContactNum   = custreq.Sphone;

            ord.ReferenceNo     = custreq.Refernce;
            ord.BillingAddress  = (custreq.BAdd1 + "#" + custreq.BAdd2 + "#" + custreq.BAdd3 + "#" + custreq.BCityName + "#" + custreq.BState + "#" + custreq.BZip + "#" + custreq.BCountryName);
            ord.ShippingAddress = (custreq.SAdd1 + "#" + custreq.SAdd2 + "#" + custreq.SAdd3 + "#" + custreq.SCityName + "#" + custreq.SState + "#" + custreq.SZip + "#" + custreq.SCountryName);
            if (!string.IsNullOrEmpty(UserID))
            {
                ord.UserId = Convert.ToInt64(UserID);
            }


            int cstOrdr = SaveCustOrder(ord);

            SaveTempOrder.TempOrderID = ord.OrderId;
            if (SaveTempOrder.TempOrderID != 0)
            {
                if (!string.IsNullOrEmpty(custreq.ApproverDetails))
                {
                    var            Data            = JsonConvert.DeserializeObject <List <ApproverDetail> >(custreq.ApproverDetails);
                    ApproverDetail ApproverDetails = new ApproverDetail();
                    for (int i = 0; i < Data.Count; i++)
                    {
                        ApproverDetails = Data[i];
                        OrderApprover orda = new OrderApprover();
                        orda.OrderId = ord.OrderId;
                        orda.Serial  = i + 1; // Need to ask customer
                        orda.UserId  = ord.UserId;
                        if (ApproverDetails.AprName != null && ApproverDetails.AprEmail != null)
                        {
                            if (!string.IsNullOrEmpty(ApproverDetails.AprId))
                            {
                                orda.OAId = Convert.ToInt64(orda.OAId);
                            }

                            orda.ApproverName  = ApproverDetails.AprName;
                            orda.ApproverTitle = ApproverDetails.AprTitle;
                            orda.ApproverEmail = ApproverDetails.AprEmail;
                            orda.isLoggedin    = true; // Need to ask customer
                            orda.isApproved    = true; // Need to ask customer
                            int ordap = SaveCustOrderApprover(orda);
                        }
                    }
                }
            }

            OrderIDdet.Add(SaveTempOrder);
            OrderIDdet.Add(2);

            return(OrderIDdet);
        }