Ejemplo n.º 1
0
        public SaveTempOrder AddOrder(Order order)
        {
            SaveTempOrder SaveTempOrder   = new SaveTempOrder();
            int           orderId         = 0;
            string        insertProcedure = "[CreatNewOrderTemp]";

            if (order.OrderId == 0)
            {
                insertProcedure = "[CreatNewOrderTemp]";
            }
            else
            {
                insertProcedure = "[UpdateNewOrderTemp]";
            }

            SqlCommand insertCommand = new SqlCommand(insertProcedure, connection);

            insertCommand.CommandType = CommandType.StoredProcedure;
            if (order.OrderId != 0)
            {
                insertCommand.Parameters.AddWithValue("@OrderID", order.OrderId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@OrderID", 0);
            }

            if (!string.IsNullOrEmpty(order.ReferenceNo))
            {
                insertCommand.Parameters.AddWithValue("@ReferenceNo", order.ReferenceNo);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ReferenceNo", DBNull.Value);
            }

            if (!string.IsNullOrEmpty(order.Department))
            {
                insertCommand.Parameters.AddWithValue("@Department", order.Department);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@Department", DBNull.Value);
            }
            if (order.CustId != 0)
            {
                insertCommand.Parameters.AddWithValue("@CustId", order.CustId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@CustId", 0);
            }
            if (order.UserId != 0)
            {
                insertCommand.Parameters.AddWithValue("@UserId", order.UserId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@UserId", 0);
            }
            if (order.BranchId != 0)
            {
                insertCommand.Parameters.AddWithValue("@BranchId", order.BranchId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@BranchId", 0);
            }
            if (order.IncoTermId != 0)
            {
                insertCommand.Parameters.AddWithValue("@IncoTermId", order.IncoTermId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@IncoTermId", 0);
            }

            if (order.StatusId != 0)
            {
                insertCommand.Parameters.AddWithValue("@StatusId", order.StatusId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@StatusId", 0);
            }

            if (!string.IsNullOrEmpty(order.ShippingAddress))
            {
                insertCommand.Parameters.AddWithValue("@ShippingAddress", order.ShippingAddress);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ShippingAddress", DBNull.Value);
            }
            if (order.CountryId != 0)
            {
                insertCommand.Parameters.AddWithValue("@CountryId", order.CountryId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@CountryId", 0);
            }

            if (!string.IsNullOrEmpty(order.CountryName))
            {
                insertCommand.Parameters.AddWithValue("@CountryName", order.CountryName);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@CountryName", DBNull.Value);
            }
            if (order.CityId != 0)
            {
                insertCommand.Parameters.AddWithValue("@CityId", order.CityId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@CityId", 0);
            }

            if (!string.IsNullOrEmpty(order.CityName))
            {
                insertCommand.Parameters.AddWithValue("@CityName", order.CityName);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@CityName", DBNull.Value);
            }
            if (!string.IsNullOrEmpty(order.BillingAddress))
            {
                insertCommand.Parameters.AddWithValue("@BillingAddress", order.BillingAddress);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@BillingAddress", DBNull.Value);
            }
            if (!string.IsNullOrEmpty(order.CustomerComments))
            {
                insertCommand.Parameters.AddWithValue("@CustomerComments", order.CustomerComments);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@CustomerComments", DBNull.Value);
            }

            if (order.Feight != 0)
            {
                insertCommand.Parameters.AddWithValue("@Feight", order.Feight);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@Feight", 0);
            }

            if (order.IsSalesOrder != false)
            {
                insertCommand.Parameters.AddWithValue("@IsSalesOrder", order.IsSalesOrder);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@IsSalesOrder", 0);
            }
            if (order.SalesOrderNo != null)
            {
                insertCommand.Parameters.AddWithValue("@SalesOrderNo", order.SalesOrderNo);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@SalesOrderNo", DBNull.Value);
            }

            if (order.ContactName != null)
            {
                insertCommand.Parameters.AddWithValue("@ContactName", order.ContactName);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ContactName", DBNull.Value);
            }

            if (order.ContactNum != null)
            {
                insertCommand.Parameters.AddWithValue("@ContactNum", order.ContactNum);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ContactNum", DBNull.Value);
            }

            if (order.ContactEmail != null)
            {
                insertCommand.Parameters.AddWithValue("@ContactEmail", order.ContactEmail);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ContactEmail", DBNull.Value);
            }
            if (order.isClosed != false)
            {
                insertCommand.Parameters.AddWithValue("@isClosed", order.isClosed);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@isClosed", 0);
            }
            if (order.isDeleted != false)
            {
                insertCommand.Parameters.AddWithValue("@isDeleted", order.isDeleted);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@isDeleted", 0);
            }

            if (!string.IsNullOrEmpty(order.DeletedReason))
            {
                insertCommand.Parameters.AddWithValue("@DeletedReason", order.isDeleted);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@DeletedReason", DBNull.Value);
            }
            insertCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int);
            insertCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output;

            insertCommand.Parameters.Add("@OrderIDout", System.Data.SqlDbType.Int);
            insertCommand.Parameters["@OrderIDout"].Direction = ParameterDirection.Output;
            try
            {
                int count = 0;
                connection.Open();
                insertCommand.ExecuteNonQuery();
                if (insertCommand.Parameters["@ReturnValue"].Value != DBNull.Value)
                {
                    count = System.Convert.ToInt32(insertCommand.Parameters["@ReturnValue"].Value);
                    SaveTempOrder.RetVal = count;
                }
                if (order.OrderId == 0)
                {
                    if (insertCommand.Parameters["@OrderIDout"].Value != DBNull.Value)
                    {
                        orderId = System.Convert.ToInt32(insertCommand.Parameters["@OrderIDout"].Value);
                        SaveTempOrder.TempOrderID = orderId;
                    }
                }



                return(SaveTempOrder);
            }
            catch (Exception ex)
            {
                log.logErrorMessage("OrderData.AddOrder");
                log.logErrorMessage(ex.StackTrace);
                return(SaveTempOrder);
            }
            finally
            {
                connection.Close();
            }
        }
        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);
        }