public ActionResult DisplayCopyFromPackageDialog(int? quotationID)
        {
            bool isSuccess = true;
            StringBuilder htmlString = new StringBuilder();

            try
            {
                CopyFromPackageModel model = new CopyFromPackageModel()
                {
                    quotationID = quotationID.Value
                };
                htmlString.Append(this.RenderPartialViewToString(string.Format(_ViewPath, "CopyFromPackageDialog"), model));
            }
            catch
            {
                isSuccess = false;
            }
            return Json(
                new
                {
                    isSuccess = isSuccess,
                    htmlString = htmlString.ToString()
                });
        }
        public ActionResult CopyFromPackageSave(CopyFromPackageModel model)
        {
            bool isSuccess = true;
            string errorType = string.Empty;
            try
            {
                if (model.quotationPackageID.HasValue)
                {
                    IEnumerable<recsys_quotation_package_items> quotationPackageItems = (from qpi in this._db.recsys_quotation_package_items
                                                                                         where qpi.quotation_package_id == model.quotationPackageID && qpi.status == 1
                                                                                         orderby qpi.nSequence
                                                                                         select qpi).ToList();
                    if (quotationPackageItems != null && quotationPackageItems.Count() > 0)
                    {
                        int? lastSequence = (from r in this._db.recsys_relate
                                            join qi in this._db.recsys_quotation_items on r.id2 equals qi.id
                                            where r.table1 == "quotation" && r.table2 == "quotation_items" && r.id1 == model.quotationID
                                            orderby qi.nSequence descending
                                            select qi.nSequence).FirstOrDefault();

                        int currentSequence = lastSequence.HasValue ? lastSequence.Value + 1 : 1;
                        Member _member = new Member("users");
                        int? userID = (int?)_member.infoBySession("id");
                        foreach (recsys_quotation_package_items quotationPackageItem in quotationPackageItems)
                        {
                            #region Create Quotation Item
                            recsys_quotation_items quotationItem = new recsys_quotation_items
                            {
                                code = quotationPackageItem.code,
                                detail = quotationPackageItem.detail_chi,
                                detail2 = quotationPackageItem.detail_eng,
                                nSequence = currentSequence,
                                price = quotationPackageItem.price,
                                last_update = DateTime.Now,
                                update_user_id = userID
                            };

                            this._db.recsys_quotation_items.AddObject(quotationItem);
                            this._db.SaveChanges(); //for getting quotation item id
                            #endregion Create Quotation Item

                            #region Create Relate Record
                            recsys_relate relate = new recsys_relate
                            {
                                table1 = "quotation",
                                table2 = "quotation_items",
                                id1 = model.quotationID,
                                id2 = quotationItem.id
                            };

                            this._db.recsys_relate.AddObject(relate);
                            this._db.SaveChanges();
                            #endregion Create Relate Record

                            currentSequence++;
                        }
                    }
                }
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return Json(new { isSuccess = isSuccess, errorType = errorType });
        }