/// <summary>
        /// This method is used to add or edit purchase quotation
        /// </summary>
        /// <param name="quotationData"></param>
        /// <returns></returns>
        public int AddUpdateQuotation(SalesQuotationForm quotationData)
        {
            int autoId = 0;
            //Add purchase quotation
            SalesQuotation obj = new SalesQuotation();

            obj.ID             = quotationData.Quotation.ID;
            obj.Cus_Id         = quotationData.Quotation.CustomerID;
            obj.Salesman       = quotationData.Quotation.SalesmanID;
            obj.SQ_Conv_to_SO  = quotationData.Quotation.SQ_Conv_to_SO;
            obj.SQ_Conv_to_SI  = quotationData.Quotation.SQ_Conv_to_SI;
            obj.SQ_Date        = quotationData.Quotation.QuotationDate;
            obj.SQ_GST_Amt     = Convert.ToDecimal(quotationData.Quotation.TotalTax);
            obj.SQ_No          = quotationData.Quotation.QuotationNo;
            obj.SQ_TandC       = quotationData.Quotation.TermsAndConditions;
            obj.SQ_Tot_aft_Tax = Convert.ToDecimal(quotationData.Quotation.TotalAfterTax);
            obj.SQ_Tot_bef_Tax = Convert.ToDecimal(quotationData.Quotation.TotalBeforeTax);
            obj.SQ_Valid_for   = quotationData.Quotation.ValidForDays;
            obj.Exc_Inc_GST    = quotationData.Quotation.ExcIncGST;
            obj.IsDeleted      = false;

            try
            {
                using (SASEntitiesEDM entities = new SASEntitiesEDM())
                {
                    if (entities.SalesQuotations.AsNoTracking().FirstOrDefault(x => x.ID == quotationData.Quotation.ID) == null)
                    {
                        //obj.CreatedBy = quotationData.SQModel.CreatedBy;
                        obj.CreatedDate = DateTime.Now;
                        entities.SalesQuotations.Add(obj);
                        entities.SaveChanges();
                        autoId = obj.ID;
                    }
                    else
                    {
                        // obj.ModifiedBy = quotationData.SQModel.ModifiedBy;
                        obj.ModifiedDate          = DateTime.Now;
                        entities.Entry(obj).State = EntityState.Modified;
                        autoId = entities.SaveChanges();
                    }
                    if (autoId > 0)
                    {
                        SalesQuotationDetail SQDetails;
                        if (quotationData.QuotationDetails != null)
                        {
                            foreach (SalesQuotationDetailEntity SQDetailEntity in quotationData.QuotationDetails)
                            {
                                SQDetails             = new SalesQuotationDetail();
                                SQDetails.SQ_ID       = autoId;
                                SQDetails.SQ_No       = SQDetailEntity.SQNo;
                                SQDetails.PandS_Code  = SQDetailEntity.PandSCode;
                                SQDetails.PandS_Name  = SQDetailEntity.PandSName;
                                SQDetails.SQ_Amount   = SQDetailEntity.SQAmount;
                                SQDetails.SQ_Discount = SQDetailEntity.SQDiscount;
                                SQDetails.SQ_No       = SQDetailEntity.SQNo;
                                SQDetails.SQ_Price    = Convert.ToDecimal(SQDetailEntity.SQPrice);
                                SQDetails.SQ_Qty      = SQDetailEntity.SQQty;
                                SQDetails.GST_Code    = SQDetailEntity.GSTCode;
                                SQDetails.GST_Rate    = SQDetailEntity.GSTRate;

                                if (entities.SalesQuotationDetails.AsNoTracking().FirstOrDefault(x => x.ID == SQDetailEntity.ID) == null)
                                {
                                    entities.SalesQuotationDetails.Add(SQDetails);
                                    entities.SaveChanges();
                                }
                                else
                                {
                                    entities.Entry(SQDetails).State = EntityState.Modified;
                                    entities.SaveChanges();
                                }
                            }
                        }
                    }
                }
                return(autoId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int UpdationQuotation(SalesQuotationForm quotationData)
        {
            try
            {
                using (SASEntitiesEDM entities = new SASEntitiesEDM())
                {
                    SalesQuotation obj = entities.SalesQuotations.Where(e => e.SQ_No == quotationData.Quotation.QuotationNo
                                                                        ).SingleOrDefault();
                    if (obj != null)
                    {
                        //obj.ID = quotationData.Quotation.ID;
                        obj.Cus_Id = quotationData.Quotation.CustomerID;
                        // obj.SQ_Conv_to_SO = quotationData.Quotation.SQ_Conv_to_SO;
                        // obj.SQ_Conv_to_SI = quotationData.Quotation.SQ_Conv_to_SI;
                        obj.SQ_Date        = Convert.ToDateTime(quotationData.Quotation.QuotationDateStr);
                        obj.SQ_GST_Amt     = Convert.ToDecimal(quotationData.Quotation.TotalTax);
                        obj.SQ_No          = quotationData.Quotation.QuotationNo;
                        obj.SQ_TandC       = quotationData.Quotation.TermsAndConditions;
                        obj.Salesman       = quotationData.Quotation.SalesmanID;
                        obj.SQ_Tot_aft_Tax = Convert.ToDecimal(quotationData.Quotation.TotalAfterTax);
                        obj.SQ_Tot_bef_Tax = Convert.ToDecimal(quotationData.Quotation.TotalBeforeTax);
                        obj.SQ_Valid_for   = quotationData.Quotation.ValidForDays;
                        obj.Exc_Inc_GST    = quotationData.Quotation.ExcIncGST;
                        obj.ModifiedDate   = DateTime.Now;
                        entities.SaveChanges();
                    }

                    var objSales = entities.SalesQuotationDetails.Where
                                       (e => e.SQ_ID == obj.ID).ToList();
                    if (objSales != null)
                    {
                        foreach (var item in objSales)
                        {
                            entities.SalesQuotationDetails.Remove(item);
                            entities.SaveChanges();
                        }
                    }
                    SalesQuotationDetail SQDetails;
                    if (quotationData.QuotationDetails != null)
                    {
                        foreach (SalesQuotationDetailEntity SQDetailEntity in quotationData.QuotationDetails)
                        {
                            SQDetails             = new SalesQuotationDetail();
                            SQDetails.SQ_ID       = obj.ID;
                            SQDetails.SQ_No       = SQDetailEntity.SQNo;
                            SQDetails.PandS_Code  = SQDetailEntity.PandSCode;
                            SQDetails.PandS_Name  = SQDetailEntity.PandSName;
                            SQDetails.SQ_Amount   = SQDetailEntity.SQAmount;
                            SQDetails.SQ_Discount = SQDetailEntity.SQDiscount;
                            SQDetails.SQ_No       = SQDetailEntity.SQNo;
                            SQDetails.SQ_Price    = Convert.ToDecimal(SQDetailEntity.SQPrice);
                            SQDetails.SQ_Qty      = SQDetailEntity.SQQty;
                            SQDetails.GST_Code    = SQDetailEntity.GSTCode;
                            SQDetails.GST_Rate    = SQDetailEntity.GSTRate;

                            entities.SalesQuotationDetails.Add(SQDetails);
                            entities.SaveChanges();
                        }
                    }
                    return(obj.ID);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }