public Boolean SaveRutf(string order_no)
        {
            try
            {
                if (GetRecordByKeyRUtf(order_no).Count > 0)
                {
                    List <Order_RUTF_Details> m = new List <Order_RUTF_Details>();
                    m = GetRecordByKeyRUtf(order_no);
                    //DateTime eDate = m.;
                    DateTime date = System.Convert.ToDateTime(context.Order_RUTF_Header.FirstOrDefault(a => a.OrderNumber == order_no).DatePrepared);

                    foreach (var n in m)
                    {
                        if (n.Quantity_Allocated > 0)
                        {
                            DateTime pDate       = date;// System.Convert.ToDateTime(n.Order_ViralLoadReagents_Header.DatePrepared);
                            int?     facility    = n.FacilityCode;
                            int      productcode = n.ProductCode;
                            var      sapcode     = context.A_Product.FirstOrDefault(a => a.product_code == n.ProductCode);
                            if (sapcode.SAP_code != null)
                            {
                                productcode = Convert.ToInt32(sapcode.SAP_code);
                            }
                            var x = new SAP_ExportDocumentLines
                            {
                                OrderNumber        = n.OrderNumber,
                                ItemCode           = productcode,
                                CurrentRecord      = true,
                                RecordReadBySAP    = false,
                                DocNum             = System.Convert.ToString(System.Convert.ToDateTime(pDate).Day + "" + System.Convert.ToDateTime(pDate).Month + "" + System.Convert.ToDateTime(pDate).Year + "" + facility),
                                QuantityAllocated  = Convert.ToInt32(n.Quantity_Allocated),
                                QuantityOrdered    = Convert.ToInt32(n.QuantityRequired),
                                CurrentRecordOnSAP = true,
                                AddedDate          = System.DateTime.Now,
                                AddedBy            = new UserManagement().getCurrentuser(),
                            };
                            if (GetRecord(order_no, x.ItemCode).Count > 0)
                            {
                            }
                            else
                            {
                                context.SAP_ExportDocumentLines.Add(x);
                                context.SaveChanges();
                            }
                        }
                    }

                    return(true);
                }
                else
                {
                    // existing_records = true;
                    return(false);
                }
            }
            catch (Exception x)
            {
                throw (x);
            }
        }
        public Boolean SaveLab(string order_no)
        {
            try
            {
                if (GetRecordByKeyLab(order_no).Count > 0)
                {
                    List <View_Order_Lab_SAP_Export_Details> m = new List <View_Order_Lab_SAP_Export_Details>();
                    m = GetRecordByKeyLab(order_no);
                    //DateTime eDate = m.;
                    DateTime date = System.Convert.ToDateTime(context.View_Order_Lab_SAP_Export_Details.FirstOrDefault(a => a.OrderNumber == order_no).DatePrepared);

                    foreach (var n in m)
                    {
                        if (n.Quantity_Allocated > 0)
                        {
                            DateTime pDate       = date;//System.Convert.ToDateTime(n.DatePrepared);
                            int?     facility    = n.FacilityCode;
                            int      productcode = n.ProductCode;
                            var      pro         = context.A_Product.FirstOrDefault(e => e.product_code == n.ProductCode);
                            if (!string.IsNullOrEmpty(pro.SAP_code))
                            {
                                string r = pro.SAP_code.Replace('"', ' ').Trim();
                                productcode = Convert.ToInt32(r);
                            }
                            var x = new SAP_ExportDocumentLines
                            {
                                OrderNumber        = n.OrderNumber,
                                ItemCode           = productcode,
                                CurrentRecord      = true,
                                RecordReadBySAP    = false,
                                DocNum             = System.Convert.ToString(System.Convert.ToDateTime(pDate).Day + "" + System.Convert.ToDateTime(pDate).Month + "" + System.Convert.ToDateTime(pDate).Year + "" + facility),
                                QuantityAllocated  = Convert.ToInt32(n.Quantity_Allocated),
                                QuantityOrdered    = Convert.ToInt32(n.Quantity_Required),
                                CurrentRecordOnSAP = true,
                                AddedDate          = System.DateTime.Now,
                                AddedBy            = new UserManagement().getCurrentuser(),
                            };

                            if (GetRecord(order_no, x.ItemCode).Count > 0)
                            {
                            }
                            else
                            {
                                context.SAP_ExportDocumentLines.Add(x);
                                context.SaveChanges();
                            }
                        }
                    }

                    return(true);
                }
                else
                {
                    // existing_records = true;
                    return(false);
                }
            }
            catch (Exception x)
            {
                throw (x);
            }
        }