public ActionResult SaveVanBanDen(HSCV_VANBANDEN entity, FormCollection fc, IEnumerable <HttpPostedFileBase> filebase, string[] filename, string[] FOLDER_ID)
        {
            try
            {
                AssignUserInfo();

                UploadFileTool uploadFileTool = new UploadFileTool();
                hscvVanBanDenBusiness = Get <HSCV_VANBANDENBusiness>();
                wfProcessBusiness     = Get <WF_PROCESSBusiness>();
                dmDanhMucDataBusiness = Get <DM_DANHMUC_DATABusiness>();

                entity.SOHIEU            = fc["SOHIEU"].Trim();
                entity.TRICHYEU          = fc["TRICHYEU"].Trim();
                entity.SOTRANG           = fc["SOTRANG"].ToIntOrZero();
                entity.LOAIVANBAN_ID     = fc["LOAIVANBAN_ID"].ToIntOrZero();
                entity.DONVI_ID          = fc["DONVI_ID"].ToIntOrZero();
                entity.LINHVUCVANBAN_ID  = fc["LINHVUCVANBAN_ID"].ToIntOrZero();
                entity.DOKHAN_ID         = fc["DOKHAN_ID"].ToIntOrZero();
                entity.NGAY_HIEULUC      = fc["NGAY_HIEULUC"].ToDateTime();
                entity.NGAYHET_HIEULUC   = fc["NGAYHET_HIEULUC"].ToDateTime();
                entity.NGAY_VANBAN       = fc["NGAY_VANBAN"].ToDateTime();
                entity.NGAY_BANHANH      = fc["NGAY_BANHANH"].ToDateTime();
                entity.NGUOIKY           = !string.IsNullOrEmpty(fc["NGUOIKY"]) ? fc["NGUOIKY"].Trim() : string.Empty;
                entity.CHUCVU            = !string.IsNullOrEmpty(fc["CHUCVU"]) ? fc["CHUCVU"].Trim() : string.Empty;
                entity.NOIDUNG           = !string.IsNullOrEmpty(fc["NOIDUNGVANBAN"]) ? fc["NOIDUNGVANBAN"].Trim() : string.Empty;
                entity.DOMAT_ID          = fc["DOMAT_ID"].ToIntOrZero();
                entity.SOVANBANDEN_ID    = fc["SOVANBANDEN_ID"].ToIntOrZero();
                entity.SODITHEOSO        = fc["SODITHEOSO"].Trim();
                entity.NGAYCONGTAC       = fc["NGAYCONGTAC"].ToDateTime();
                entity.GIO_CONGTAC       = fc["GIO_CONGTAC"].ToIntOrNULL();
                entity.PHUT_CONGTAC      = fc["PHUT_CONGTAC"].ToIntOrNULL();
                entity.SODITHEOSO_NUMBER = int.Parse(entity.SODITHEOSO);
                entity.MA_DANGKY         = fc["MA_DANGKY"];
                entity.LOAI_COQUAN_ID    = fc["LOAI_COQUAN_ID"].ToIntOrNULL();
                entity.SO_BAN            = fc["SO_BAN"].ToIntOrNULL();
                entity.THONGTIN_LOAI_ID  = fc["THONGTIN_LOAI_ID"].ToIntOrNULL();
                entity.TACGIA            = fc["TACGIA"];
                entity.CONGVAN_DEN_ID    = fc["CONGVAN_DEN_ID"].ToIntOrNULL();
                entity.THOIHAN_GIAIQUYET = fc["THOIHAN_GIAIQUYET"].ToDateTime();
                List <long> ListUser = new List <long>();
                ListUser.Add(currentUser.ID);
                if (entity.ID == 0)
                {
                    entity.NGAYTAO  = DateTime.Now;
                    entity.NGUOITAO = currentUser.ID;
                    entity.NGAYSUA  = DateTime.Now;
                    entity.NGUOISUA = currentUser.ID;
                    hscvVanBanDenBusiness.Save(entity);
                    #region insert elastic search
                    ElasticModel model = ElasticModel.ConvertVanBanDen(entity, ListUser);
                    ElasticSearch.insertDocument(model, model.Id.ToString(), ElasticType.VanBanDen);
                    #endregion
                    JsonResultBO processResult = wfProcessBusiness.AddFlow(entity.ID, MODULE_CONSTANT.VANBANDEN, currentUser);
                    if (processResult.Status)
                    {
                        uploadFileTool.UploadFiles(filebase, extensionOfVanBanDen.Split(',').ToList(), uploadFolder, filename, entity.ID, LOAITAILIEU.VANBANDEN, maxSizeOfVanBanDen, currentUser);
                    }
                    //cập nhật số đi theo sổ
                    dmDanhMucDataBusiness.UpdateSoVanBan(entity.SOVANBANDEN_ID.GetValueOrDefault(), entity.SODITHEOSO.ToIntOrZero());
                }
                else
                {
                    HSCV_VANBANDEN dbEntity = hscvVanBanDenBusiness.Find(entity.ID);

                    dbEntity.SOHIEU           = entity.SOHIEU;
                    dbEntity.TRICHYEU         = entity.TRICHYEU;
                    dbEntity.SOTRANG          = entity.SOTRANG;
                    dbEntity.DONVI_ID         = entity.DONVI_ID;
                    dbEntity.LOAIVANBAN_ID    = entity.LOAIVANBAN_ID;
                    dbEntity.LINHVUCVANBAN_ID = entity.LINHVUCVANBAN_ID;
                    dbEntity.DOKHAN_ID        = entity.DOKHAN_ID;
                    dbEntity.NGAY_HIEULUC     = entity.NGAY_HIEULUC;
                    dbEntity.NGAYHET_HIEULUC  = entity.NGAYHET_HIEULUC;
                    dbEntity.NGAY_VANBAN      = entity.NGAY_VANBAN;
                    dbEntity.NGAY_BANHANH     = entity.NGAY_BANHANH;
                    dbEntity.NGUOIKY          = entity.NGUOIKY;
                    dbEntity.CHUCVU           = entity.CHUCVU;
                    dbEntity.NOIDUNG          = entity.NOIDUNG;
                    dbEntity.DOMAT_ID         = entity.DOMAT_ID;

                    dbEntity.NGAYCONGTAC       = entity.NGAYCONGTAC;
                    dbEntity.SOVANBANDEN_ID    = entity.SOVANBANDEN_ID;
                    dbEntity.SODITHEOSO        = entity.SODITHEOSO;
                    dbEntity.SODITHEOSO_NUMBER = entity.SODITHEOSO_NUMBER;

                    dbEntity.GIO_CONGTAC  = entity.GIO_CONGTAC;
                    dbEntity.PHUT_CONGTAC = entity.PHUT_CONGTAC;

                    dbEntity.MA_DANGKY              = entity.MA_DANGKY;
                    dbEntity.LOAI_COQUAN_ID         = entity.LOAI_COQUAN_ID;
                    dbEntity.SO_BAN                 = entity.SO_BAN;
                    dbEntity.THONGTIN_LOAI_ID       = entity.THONGTIN_LOAI_ID;
                    dbEntity.TACGIA                 = entity.TACGIA;
                    dbEntity.CONGVAN_DEN_ID         = entity.CONGVAN_DEN_ID;
                    dbEntity.THOIHAN_GIAIQUYET      = entity.THOIHAN_GIAIQUYET;
                    dbEntity.NGUOINHAN_TRUCTIEP_IDS = entity.NGUOINHAN_TRUCTIEP_IDS;
                    dbEntity.NGAYSUA                = DateTime.Now;
                    dbEntity.NGUOISUA               = currentUser.ID;
                    hscvVanBanDenBusiness.Save(dbEntity);

                    uploadFileTool.UploadFiles(filebase, extensionOfVanBanDen.Split(',').ToList(), uploadFolder, filename, dbEntity.ID, LOAITAILIEU.VANBANDEN, maxSizeOfVanBanDen, currentUser);

                    #region update elastic
                    ElasticModel model = ElasticModel.ConvertVanBanDen(dbEntity, ListUser);
                    ElasticSearch.updateDocument(model, model.Id.ToString(), ElasticType.VanBanDen);
                    #endregion
                }
                return(RedirectToAction("DetailVanBanDen", new { id = entity.ID }));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index"));
            }
        }