public ActionResult Update(string counterPartyGroup, long counterPartyId, string cifCounterParty, int isInau)
        {
            TheSession.Remove(_strSectionProduct); //xóa section list product
            CPProductGetDetailViewModel input = new CPProductGetDetailViewModel();

            input.cifCounterParty   = cifCounterParty;
            input.counterPartyGroup = counterPartyGroup;
            input.counterPartyId    = counterPartyId;
            input.isInau            = isInau;
            input.userId            = RDAuthorize.UserId;
            var result = _cPProductService.getDetailCpProdCommis(input);

            #region
            CPProductViewModel model = new CPProductViewModel();
            List <CPProductImportProductModel>       productList   = new List <CPProductImportProductModel>();
            List <CPProductImportCommisionListModel> commisionList = new List <CPProductImportCommisionListModel>();
            List <AttachmentViewModel> fileList = new List <AttachmentViewModel>();

            if (result != null)
            {
                Library.TransferData(result, ref model);//main
            }

            if (result.fileList != null && result.fileList.Any())
            {
                Library.TransferData(result.fileList, ref fileList);
            }

            if (result.productList != null && result.productList.Any())
            {
                Library.TransferData(result.productList, ref productList);
                foreach (var item in result.productList)
                {
                    if (item.commisionList != null && item.commisionList.Any())
                    {
                        foreach (var item1 in item.commisionList)
                        {
                            CPProductImportCommisionListModel tempModel = new CPProductImportCommisionListModel();
                            Library.TransferData(item1, ref tempModel);
                            tempModel.SelectList  = productList;
                            tempModel.productCode = productList.SingleOrDefault(x => x.productId == tempModel.productId).productCode;
                            commisionList.Add(tempModel);
                        }
                    }
                }
            }
            model.commisionList = commisionList;
            model.productList   = productList;
            model.viewMode      = ViewModeCons.UPDATE;
            ViewBag.viewMode    = ViewModeCons.UPDATE;
            ViewBag.fileList    = fileList;
            #endregion
            return(View("Create", model));
        }
        public JsonResult ImportCommisionList(HttpPostedFileBase importCommisionList)
        {
            string fileName = "";
            object ls;
            object retList = null;

            try
            {
                var file = importCommisionList;
                if (file != null)
                {
                    string[] extFile = new string[] { "xlsx" };
                    fileName = string.Format("{0}\\{1}{2}", Server.MapPath("~/Content/Uploads"), DateTime.Now.ToString("yyyyMMddHHmmss"), System.IO.Path.GetExtension(file.FileName));
                    if (fileName.EndsWith(".xlsx", StringComparison.CurrentCultureIgnoreCase))
                    {
                        file.SaveAs(fileName);
                    }

                    Reader           reader = new Reader(fileName);
                    IDataTransformer podata = new DataTransformer();
                    ls = reader.GetData <CPProductImportTempCommisionListModel>(podata);
                    if (ls != null)
                    {
                        int idx = 1;
                        List <CPProductImportCommisionListModel> lsImport  = new List <CPProductImportCommisionListModel>();
                        List <CPProductImportProductModel>       lsProduct = new List <CPProductImportProductModel>();
                        object temp;
                        TheSession.TryGet(_strSectionProduct, out temp);
                        if (temp != null)
                        {
                            lsProduct = (List <CPProductImportProductModel>)temp;
                        }
                        if (lsProduct != null && lsProduct.Any())
                        {
                            foreach (var itx in ls as List <CPProductImportTempCommisionListModel> )
                            {
                                if (!string.IsNullOrEmpty(itx.productCode))
                                {
                                    string strProductCode = itx.productCode.FilterSpecial();
                                    string strMessage     = string.Empty;
                                    bool   isExists       = false;

                                    if (lsProduct != null && lsProduct.Any())
                                    {
                                        lsProduct = lsProduct.Where(x => string.IsNullOrEmpty(x.errorMessage)).ToList();
                                        isExists  = lsProduct.Any(x => x.productCode.ToUpper().Trim().Equals(strProductCode.ToUpper().Trim()));
                                    }
                                    else
                                    {
                                        strMessage += " Không tìm thấy danh sách mã sản phẩm";
                                    }
                                    if (!isExists)
                                    {
                                        strMessage += " Mã sản phẩm không tồn tại";
                                    }

                                    if (itx.effectedFromDate == null)
                                    {
                                        strMessage += " Thiếu trường hiệu lực từ ngày";
                                    }
                                    else
                                    {
                                        if (DateTime.Parse(itx.effectedFromDate.ToString()).Ticks < DateTime.Now.Date.Ticks)
                                        {
                                            strMessage += " Ngày hiệu lực từ ngày phải lớn hơn ngày hiện tại";
                                        }
                                    }
                                    if (itx.effectedToDate == null)
                                    {
                                        strMessage += " Thiếu trường hiệu lực đến ngày";
                                    }
                                    else
                                    {
                                        if (DateTime.Parse(itx.effectedToDate.ToString()).Ticks < DateTime.Now.Date.Ticks)
                                        {
                                            strMessage += " Ngày hiệu lực đến ngày phải lớn hơn ngày hiện tại";
                                        }
                                    }
                                    var item = new CPProductImportCommisionListModel
                                    {
                                        productCode      = strProductCode,
                                        productName      = itx.productName,
                                        effectedFromDate = itx.effectedFromDate != null?DateTime.Parse(itx.effectedFromDate.ToString()) : new DateTime(),
                                                               effectedToDate = itx.effectedToDate != null?DateTime.Parse(itx.effectedToDate.ToString()) : new DateTime(),
                                                                                    totalCommisRate   = (itx.agencyCommisRate ?? 0) + (itx.supportCommisRate ?? 0) + (itx.serviceCostRate ?? 0),
                                                                                    agencyCommisRate  = (itx.agencyCommisRate ?? 0),
                                                                                    supportCommisRate = (itx.supportCommisRate ?? 0),
                                                                                    serviceCostRate   = (itx.serviceCostRate ?? 0),
                                                                                    commisRate        = (itx.commisRate ?? 0),
                                                                                    errorMessage      = strMessage
                                    };
                                    item.remainRate = item.totalCommisRate - item.commisRate;
                                    item.SelectList = new List <SelectListItem>();
                                    item.SelectList = lsProduct;
                                    lsImport.Add(item);
                                    idx++;
                                }
                            }
                            retList = lsImport;
                            TheSession.TrySet(_strSectionCommisionList, retList);
                            return(Json(new { Code = 0, Message = RenderPartialViewToString("~/Areas/CPProduct/Views/Shared/_templateCommissionListImport.cshtml", retList) }));
                        }
                        else
                        {
                            return(Json(new { Code = -1, Message = "Không tìm thấy danh sách sản phẩm" }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HDBH.Log.WriteLog.Error("ManagerController => ImportCommisionList", ex);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    System.IO.File.Delete(fileName);
                }
            }
            return(Json(new { Code = -1, Message = "Không tìm thấy danh sách sản phẩm" }));
        }