コード例 #1
0
        public List <CasecAccountInfo> Provide(FormDataCollection form)
        {
            var contactId = form.Get("contactId").ToInt32();
            var list      = CasecAccountRepository.Provide(contactId);

            if (!list.IsNullOrEmpty())
            {
                foreach (var item in list)
                {
                    item.DateTimeString    = item.DateTime.ToString("dd/MM/yyyy");
                    item.CreatedDateString = item.CreatedDate.ToString("dd/MM/yyyy");
                    item.StatusString      = ObjectExtensions.GetEnumDescription((StatusCasecType)item.StatusCasecAccountId);

                    // Call WS
                    if (item.StatusCasecAccountId == (int)StatusCasecType.Used)
                    {
                        var result = (new HelpUtils()).SendCasecAccount(item);
                        if (result.Code == 0)
                        {
                            ContactLevelInfoRepository.UpdateHasCasecAccount(contactId, true);
                        }
                    }
                }
                return(list);
            }
            return(null);
        }
コード例 #2
0
ファイル: BCModelContact.cs プロジェクト: HungNV88/CRM
        public static List <T> Create <T>(List <ContactInfo> infos) where T : BCModelContact
        {
            var list            = new List <T>();
            var listId          = infos.Select(c => c.Id).Distinct().ToList();
            var listTdHistories =
                infos.Where(c => c.CallInfoConsultant.IsStringNullOrEmpty()).Select(c => c.Id).Distinct().ToList();
            var xs = new XmlSerializer(typeof(List <int>));
            var ms = new MemoryStream();

            xs.Serialize(ms, listId);
            var resultXML         = Encoding.UTF8.GetString(ms.ToArray());
            var phones            = PhoneRepository.GetByContacts_Xml(resultXML);
            var contactLevelInfos = ContactLevelInfoRepository.GetInfos_Xml(resultXML);

            xs = new XmlSerializer(typeof(List <int>));
            ms = new MemoryStream();
            xs.Serialize(ms, listTdHistories);
            resultXML = Encoding.UTF8.GetString(ms.ToArray());
            var callHistories = CallHistoryRepository.GetAllByContactId_Xml(resultXML);

            foreach (var info in infos)
            {
                var t = Create <T>(info, contactLevelInfos, phones, callHistories);
                list.Add(t);
            }
            return(list);
        }
コード例 #3
0
        public Result SendRequestSB100Topica(int ContactId, int feePackageType) // tuy chon, thoa thich
        {
            var log = new TmpLogServiceInfo();

            log.Status   = 0;
            log.CallType = (int)CallType.SendRequestSB100Topica;
            log.Time     = DateTime.Now;
            try
            {
                var TVTS        = UserRepository.GetCurrentUserInfo();
                var infoContact = ContactRepository.GetInfo(ContactId);
                var infoResult  = TestResultRepository.GetResultTopicaCurent(ContactId);
                var model       = new SB100Topica();
                model.hocVienId = ContactId;
                model.ngayTest  = infoResult.TestDate;
                model.S1        = infoResult.S1;
                model.S2        = infoResult.S2;
                model.S3        = infoResult.S3;
                model.S4        = infoResult.S4;
                var phones = PhoneRepository.GetByContact(ContactId);
                foreach (var phone in phones)
                {
                    if (phone.IsPrimary == 1)
                    {
                        model.mobile = phone.PhoneNumber;
                        break;
                    }
                }
                model.tenHocVien = infoContact.Fullname;
                model.TVTS       = TVTS.UserName;

                var infoLevel = ContactLevelInfoRepository.GetInfoByContactId(ContactId);
                model.kieuHocPhiId = feePackageType; // infoLevel.FeePackageType;
                var infoUser = UserRepository.GetInfo(infoContact.UserConsultantId);


                var ws     = new WsCRMSoapClient("WsCRMSoap");
                var input  = JsonConvert.SerializeObject(model);
                var output = ws.UpdateSB100_topica(input);

                var result = JsonConvert.DeserializeObject <Result>(output);

                log.Description = result.Description + "_" + input;
                log.Status      = result.Code;
                TmpLogServiceRepository.Create(log);
                return(result);
            }
            catch (Exception ex)
            {
                var result = new Result();
                result.Code        = 1;
                result.Description = "Không gửi được thông tin tài khoản cấp cho Chuyên Môn";
                log.Description    = result.Description;
                log.Status         = result.Code;
                TmpLogServiceRepository.Create(log);
                return(result);
            }
        }
コード例 #4
0
        public JsonResult GetForFilterTeam(int branchId, int collectorId, int channelId, int importId, int levelId, int sourceTypeId, int schoolId, int statusId, int page, int rows)
        {
            var list     = new MyContactListModel();
            var lstModel = new List <ContactModel>();
            int totalRecords;
            var data = ContactRepository.GetForFilterTeam(branchId, collectorId, channelId, importId, levelId, sourceTypeId, schoolId, statusId, page, rows, out totalRecords);

            foreach (var info in data)
            {
                var objModel = ObjectHelper.Transform <ContactModel, ContactInfo>(info);
                objModel.StatusName = ObjectExtensions.GetEnumDescription((StatusType)info.StatusId);
                var contactLevel = ContactLevelInfoRepository.GetInfo(info.Id);
                if (contactLevel != null)
                {
                    objModel.Notes = contactLevel.EducationSchoolName;
                }
                var collector = CollectorRepository.GetInfo(info.CollectorId);
                var channel   = ChannelRepository.GetInfo(info.ChannelId);
                var phones    = PhoneRepository.GetByContact(info.Id);
                foreach (var phone in phones)
                {
                    if (phone.IsPrimary == 1)
                    {
                        objModel.Mobile = phone.PhoneNumber;
                    }
                    else if (phone.PhoneType == PhoneType.HomePhone.ToString())
                    {
                        objModel.Tel = phone.PhoneNumber;
                    }
                    else
                    {
                        objModel.Mobile2 = phone.PhoneNumber;
                    }
                }
                if (collector != null)
                {
                    objModel.CollectorName = collector.Name;
                }
                if (channel != null)
                {
                    objModel.ChannelName = channel.Name;
                }

                lstModel.Add(objModel);
            }
            list.UserData = totalRecords;
            list.Rows     = lstModel;
            list.Page     = page;
            list.Total    = (totalRecords / rows) + 1;
            list.Records  = rows;
            return(new JsonResult {
                Data = list, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #5
0
        // GET api/<controller>
        public ContactLevelInfoListModel Get(int collectorId, int sourceTypeId, int levelId, int channelId, int statusId, int statusMapId, int branchId, int page, int rows)
        {
            int totalRecords;
            var model = new ContactLevelInfoListModel
            {
                Rows    = ContactLevelInfoRepository.Search(collectorId, sourceTypeId, levelId, channelId, statusId, statusMapId, branchId, page, rows, out totalRecords),
                Page    = page,
                Total   = (totalRecords / rows) + 1,
                Records = rows
            };

            return(model);
        }
コード例 #6
0
ファイル: ServiceCasec.asmx.cs プロジェクト: HungNV88/CRM
 public bool SaveInfoHandover(string code, string note, int status)
 {
     try
     {
         LogHandoverAdvisorRepository.Insert_LogHandoverAdvisor(code, note, status);
         ContactLevelInfoRepository.UpdateHandoverAdvisorStatus(code, status);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #7
0
        public Result RequestLinkSb100Topica(FormDataCollection form)
        {
            var contactId = form.Get("contactId").ToInt32();
            var result    = new Result
            {
                Code = 0,
            };

            if (result.Code == 0)
            {
                ContactLevelInfoRepository.UpdateHasLinkSb100Topica(contactId, true);
            }
            return(result);
        }
コード例 #8
0
        public Result RequestSb100Topica(FormDataCollection form)
        {
            var user           = UserContext.GetCurrentUser();
            var contactId      = form.Get("contactId").ToInt32();
            var feePackageType = form.Get("feePackageType").ToInt32();
            var hocvien_name   = form.Get("hocvien_name").ToString();
            //var tvts_name_id = form.Get("tvts_name").ToInt32();
            string tvts_name = user.FullName.ToString();
            var    result    = (new HelpUtils()).SendRequestSB100Topica(contactId, feePackageType);

            if (result.Code == 0)
            {
                ContactLevelInfoRepository.UpdateHasSetSb100Topica(contactId, true);
            }

            //Send Mail
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.To.Add("*****@*****.**");
            mail.From            = new MailAddress("*****@*****.**", "Thông báo đặt hàng SB100", System.Text.Encoding.UTF8);
            mail.Subject         = "Đặt SB100";
            mail.SubjectEncoding = System.Text.Encoding.UTF8;

            //string hocvien_name = "";

            mail.Body         = tvts_name + " muốn đặt hàng SB100 cho học viên " + hocvien_name;
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml   = true;
            mail.Priority     = MailPriority.High;
            SmtpClient client = new SmtpClient();

            client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "thanghva");
            client.Port        = 587;
            client.Host        = "smtp.gmail.com";
            client.EnableSsl   = true;
            try
            {
                client.Send(mail);
            }
            catch (Exception ex)
            {
                Exception ex2          = ex;
                string    errorMessage = string.Empty;
                while (ex2 != null)
                {
                    errorMessage += ex2.ToString();
                    ex2           = ex2.InnerException;
                }
            }
            return(result);
        }
コード例 #9
0
        public Result Schedule(FormDataCollection form)
        {
            var    contactId     = form.Get("contactId").ToInt32();
            var    entityDbs     = AppointmentInterviewRepository.GetAllByContactId(contactId);
            string noteConsulant = "";
            var    userConsulant = UserContext.GetCurrentUser();

            noteConsulant = userConsulant.IsDATester == false?form.Get("notes") : "VIP+: " + form.Get("notes");

            var entity = new AppointmentInterviewInfo
            {
                ContactId         = contactId,
                Notes             = noteConsulant,
                NotesCM           = form.Get("notesCM"),
                UserId            = userConsulant.UserID,
                TimeSlotId        = form.Get("timeSlotId").ToInt32(),
                TeacherTypeId     = form.Get("teacherTypeId").ToInt32(),
                LevelTesterId     = form.Get("levelTesterId").ToInt32(),
                StatusInterviewId = form.Get("statusInterviewId").ToInt32(),
                CasecAccountId    = entityDbs.IsNullOrEmpty() ? 0 : entityDbs[0].CasecAccountId,
                AppointmentDate   = form.Get("appointmentDate").ToDateTime("ddMMyyyy") ?? DateTime.Now,
            };
            var reSchedule = form.Get("reSchedule").ToBoolean();

            entity.StatusInterviewId = reSchedule
                ? (int)StatusInterviewType.HocVienDoiLichPhongVan
                : (int)StatusInterviewType.DaDatHang;
            var result = reSchedule
                ? (new HelpUtils()).SendChangeInterviewInfo(entity)
                : (new HelpUtils()).SendInterviewInfo(entity, userConsulant.IsDATester);

            if (result.Code == 0)
            {
                result.Tag = entity.StatusInterviewId;
                AppointmentInterviewRepository.Create(entity);
                ContactLevelInfoRepository.UpdateHasAppointmentInterview(entity.ContactId, true);
            }
            return(result);
        }
コード例 #10
0
        public List <TopicaAccountInfo> Provide(FormDataCollection form)
        {
            var       contactId        = form.Get("contactId").ToInt32();
            string    linkTopicaSystem = ConfigurationManager.AppSettings["TopicaEnglishSystem"].ToString();
            WebClient client           = new WebClient();

            client.Headers["Content-type"] = "application/json";
            //string a = "http://tracnghiem.topicanative.edu.vn/webservice/rest/server.php?wstoken="+ token +"&wsfunction="+ function + "&moodlewsrestformat=json&contactid=" + contactId;
            // invoke the REST method
            byte[] data = client.DownloadData(
                linkTopicaSystem + "?wstoken=" + token + "&wsfunction=" + function + "&moodlewsrestformat=json&contactid=" + contactId);

            // put the downloaded data in a memory stream
            MemoryStream ms = new MemoryStream();

            ms = new MemoryStream(data);
            // deserialize from json
            DataContractJsonSerializer ser =
                new DataContractJsonSerializer(typeof(TopicaAccountInfo));
            TopicaAccountInfo result = ser.ReadObject(ms) as TopicaAccountInfo;

            var list = TopicaAccountRepository.UpdateTopicaAccount(contactId, result.username, result.password);

            ContactLevelInfoRepository.UpdateHasTopicaAccount(contactId, true);

            if (!list.IsNullOrEmpty())
            {
                foreach (var item in list)
                {
                    item.DateTimeString    = item.DateTime.ToString("dd/MM/yyyy");
                    item.CreatedDateString = item.CreatedDate.ToString("dd/MM/yyyy");
                    item.StatusString      = ObjectExtensions.GetEnumDescription((StatusTopicaType)item.StatusTopicaAccountId);
                }
                return(list);
            }

            return(null);
        }
コード例 #11
0
        public Result CancelSchedule(FormDataCollection form)
        {
            var contactId = form.Get("contactId").ToInt32();
            var entityDbs = AppointmentInterviewRepository.GetAllByContactId(contactId) ?? new List <AppointmentInterviewInfo>();
            var entity    = entityDbs.OrderBy(c => c.Id).LastOrDefault();

            if (entity != null)
            {
                var result = (new HelpUtils()).SendCancelInterview(entity.ContactId);
                if (result.Code == 0)
                {
                    entity.StatusInterviewId = (int)StatusInterviewType.HocVienHuyPhongVan;
                    AppointmentInterviewRepository.Update(entity);
                    ContactLevelInfoRepository.UpdateHasAppointmentInterview(entity.ContactId, false);
                }
                return(result);
            }
            return(new Result
            {
                Code = 1,
                Description = "Lịch không tồn tại, bạn phải đặt lịch trước khi hủy lịch"
            });
        }
コード例 #12
0
 // GET api/<controller>
 public IEnumerable <ContactLevelInfo> Get()
 {
     return(ContactLevelInfoRepository.GetAll());
 }
コード例 #13
0
        //
        // GET: /Admin/HandoverAdvisor/

        public ActionResult HandoverContact(int id, ContactLevelInfoModel modelCache = null)
        {
            ViewBag.SourceTypes = SourceTypeRepository.GetAll();

            var user = UserContext.GetCurrentUser();

            if (user == null)
            {
                return(RedirectToAction("FilterContactToday", "ContactFilter", new { area = "Admin" }));
            }

            var contactInfo = ContactRepository.GetInfo(id);

            if (contactInfo == null)
            {
                return(RedirectToAction("FilterContactToday", "ContactFilter", new { area = "Admin" }));
            }

            if (user.GroupConsultantType == (int)GroupConsultantType.Consultant && user.UserID != contactInfo.UserConsultantId)
            {
                return(RedirectToAction("FilterContactToday", "ContactFilter", new { area = "Admin" }));
            }

            string TransactionReason = "";

            List <LogsMoneyInfo> logMoneyInfos = MoneyLogsRepository.GetAllByContactId(id);

            foreach (var logMoney in logMoneyInfos)
            {
                TransactionReason += logMoney.NoteChuyenKhoan + "@@@";
            }

            ViewBag.Id     = id;
            ViewBag.IsView = user.UserID != contactInfo.UserConsultantId ? 1 : 0;

            if (user.GroupConsultantType == (int)GroupConsultantType.ManagerConsultant)
            {
                ViewBag.IsView = 0;
            }
            var contactLevelInfo = ContactLevelInfoRepository.GetInfoByContactId(id) ?? new ContactLevelInfo();
            var model            = InitModel(contactInfo, contactLevelInfo);

            model.ContactInfo.Consultant             = user.UserName;
            model.ContactInfo.UserName               = user.FullName; //Lay ten TVTS
            model.ContactLevelInfo.TransactionReason = TransactionReason;
            model.PhoneTVTS = user.Mobile;                            //điện thoại TVTS
            model.EmailTVTS = user.Email;                             //Email TVTS

            if (model.ContactInfo != null)
            {
                if (modelCache != null && modelCache.ContactInfo != null)
                {
                    model.ContactInfo.QualityId              = modelCache.ContactInfo.QualityId;
                    model.ContactInfo.CallInfoConsultant     = modelCache.ContactInfo.CallInfoConsultant;
                    model.ContactInfo.StatusMapConsultantId  = modelCache.ContactInfo.StatusMapConsultantId;
                    model.ContactInfo.StatusCareConsultantId = modelCache.ContactInfo.StatusCareConsultantId;
                }
                else
                {
                    model.ContactInfo.QualityId              = 0;
                    model.ContactInfo.StatusMapConsultantId  = 0;
                    model.ContactInfo.StatusCareConsultantId = 0;
                    model.ContactInfo.CallInfoConsultant     = string.Empty;
                }
            }
            return(View(model));
        }
コード例 #14
0
        public ActionResult HandoverContact(ContactLevelInfoModel model)
        {
            string linkApiHandoverAdvisor = ConfigurationManager.AppSettings["LinkAPIHandoverAdvisor"].ToString();
            //if (model.ContactLevelInfo.HandoverAdvisor == 1)
            //{
            string username = "******";
            string password = "******";

            var contactid = model.ContactInfo.Id;
            var code      = model.ContactInfo.Code;
            var phone     = model.ContactInfo.Mobile1;
            var email     = model.ContactInfo.Email;
            var fullname  = model.ContactInfo.Fullname;
            var gender_id = model.ContactInfo.Gender;
            var note      = model.ContactLevelInfo.DacDiemHocVien;

            int iFeeMoneyType         = model.ContactLevelInfo.FeeMoneyType;
            var package_want_to_learn = model.ContactLevelInfo.PackageWantToLearn;
            var level_crm             = model.ContactInfo.LevelId.ToString();
            var deposit_need          = model.ContactLevelInfo.PackagePriceSale;
            var actually_paid         = model.ContactLevelInfo.FeeEdu;
            //var technical_test = model.ContactLevelInfo.HasTestTechnical; //da kiem tra ky thuat chua
            var technical_test = 1;
            var tvts_id        = model.ContactInfo.Consultant;

            var tvts_name          = model.ContactInfo.UserName;
            var transaction_reason = model.ContactLevelInfo.TransactionReason;
            var sb100           = model.TestResultLinkSb100Info.LinkSb100 != null? model.TestResultLinkSb100Info.LinkSb100: "";
            var casec_total     = model.TestResultCasecInfo.TotalCasec;
            var toiec_total     = model.TestResultTopicaInfo.TotalTopica;
            var interview_total = model.TestResultInterviewInfo.TotalInterview;
            var tvts_phone      = Request["PhoneTVTS"].ToString();

            var time_want_to_learn = (Request["time_want_to_learn"]);

            if (!time_want_to_learn.IsStringNullOrEmpty())
            {
                time_want_to_learn += string.IsNullOrEmpty(model.Time24hWantToLearn) ? " 00:00:00" : " " + model.Time24hWantToLearn;
            }

            var tvts_email = Request["EmailTVTS"].ToString();

            int    level_study_id = Int32.Parse(Request["LevelStudyAdvisor"]);
            string level_study;

            string gender;

            if (gender_id == 1)
            {
                gender = "Nam";
            }
            else
            {
                gender = "Nữ";
            }


            if (level_study_id == 1)
            {
                level_study = "basic100";
            }
            else if (level_study_id == 2)
            {
                level_study = "basic200";
            }
            else if (level_study_id == 3)
            {
                level_study = "basic300";
            }
            else if (level_study_id == 4)
            {
                level_study = "inter100";
            }
            else if (level_study_id == 5)
            {
                level_study = "inter200";
            }
            else if (level_study_id == 6)
            {
                level_study = "inter300";
            }
            else if (level_study_id == 7)
            {
                level_study = "advan100";
            }
            else if (level_study_id == 8)
            {
                level_study = "advan200";
            }
            else if (level_study_id == 9)
            {
                level_study = "advan300";
            }
            else
            {
                level_study = "sbasic";
            }


            var client = new RestClient(linkApiHandoverAdvisor);

            client.Authenticator = new HttpBasicAuthenticator(username, password);

            var request = new RestRequest();

            if (model.ContactLevelInfo.HandoverAdvisor == 1)
            {
                request = new RestRequest("advisor_api/create_new_student_info", Method.POST);
            }
            else if (model.ContactLevelInfo.HandoverAdvisor == 3)
            {
                request = new RestRequest("advisor_api/update_new_student_info", Method.POST);
            }

            request.AddHeader("Accept", "application/json");

            request.AddParameter("key", "SSeKfm7RXCJZxnFUleFsPf63o2ymZ93fWuCmvC34");

            request.AddParameter("contact_id", code);
            request.AddParameter("phone", phone);
            request.AddParameter("email", email);
            request.AddParameter("full_name", fullname);
            request.AddParameter("gender", gender);
            request.AddParameter("package_want_to_learn", package_want_to_learn);
            request.AddParameter("lang", "vi");
            request.AddParameter("note", note);
            request.AddParameter("level_crm", "L" + level_crm);
            request.AddParameter("deposit_need", deposit_need);
            request.AddParameter("actually_paid", actually_paid);

            request.AddParameter("technical_test", technical_test);
            request.AddParameter("tvts_id", tvts_id);
            request.AddParameter("tvts_name", tvts_name);
            request.AddParameter("actually_paid", actually_paid);
            request.AddParameter("transaction_reason", transaction_reason);
            request.AddParameter("sb100", sb100);
            request.AddParameter("casec_total", casec_total);
            request.AddParameter("toiec_total", toiec_total);
            request.AddParameter("interview_total", interview_total);
            request.AddParameter("tvts_phone", tvts_phone);
            request.AddParameter("time_want_to_learn", time_want_to_learn);
            request.AddParameter("tvts_email", tvts_email);
            request.AddParameter("level_study", level_study);

            try {
                request.JsonSerializer.ContentType = "application/json; charset=utf-8";
                IRestResponse response = client.Execute(request);

                var content = response.Content;
                var input   = JsonConvert.DeserializeObject <LogTaoHocVien>(content);

                if (input.state == 1)
                {
                    ViewBag.Close   = 1;
                    ViewBag.Message = "Bàn giao thành công";
                    int value = (int)StatusHandoverAdvisor.Handover;

                    ContactLevelInfoRepository.UpdateHandoverAdvisorStatusWithContactId(contactid, value);
                    ContactLevelInfoRepository.UpdateLevelStudyAdvisor(contactid, level_study_id);

                    DateTime dt_timewanttolearn = DateTime.ParseExact(time_want_to_learn, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                    ContactLevelInfoRepository.Update_DateWantToLearn(contactid, dt_timewanttolearn);
                    //Viet them ham cap nhat da kiem tra test ky thuat
                    LogHandoverAdvisorRepository.Insert_LogHandoverAdvisor(code, "", value);

                    return(HandoverContact(model.ContactInfo.Id, model));
                }
                else
                {
                    ViewBag.Message = "Bàn giao không thành công: " + input.msg;
                    return(HandoverContact(model.ContactInfo.Id, model));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Đã có lỗi xảy ra, vui lòng thực hiện lại!";
                return(HandoverContact(model.ContactInfo.Id, model));
            }

            return(HandoverContact(model.ContactInfo.Id, model));
        }
コード例 #15
0
        public ActionResult FixedMoneyManagerConsulant(FormCollection forms)
        {
            var valueRow = Request["countRowTable"].ToInt32();

            List <ContactFixedMoney> lstInfoCts       = new List <ContactFixedMoney>();
            AllDealMoney             listDealSesssion = new AllDealMoney();

            listDealSesssion.pricing  = new List <ContactInfoMoney>();
            listDealSesssion.deposit  = new List <ContactInfoMoney>();
            listDealSesssion.transfer = new List <ContactInfoMoneyTranfer>();
            listDealSesssion.balance  = new List <ContactInfoMoneyBalance>();

            string notes = Request["NotesManagerConsulant"].ToString();

            var userTVTS = UserContext.GetCurrentUser();

            for (int i = 1; i <= valueRow; i++)
            {
                ContactInfoMoney infoCts = new ContactInfoMoney();

                infoCts.ContactId      = Request["CodeCts_" + i.ToString()].ToString();
                infoCts.UserName       = Request["NameCts_" + i.ToString()].ToString();
                infoCts.UserPhone      = forms.Get("MobileCts_" + i.ToString()).ToString();
                infoCts.UserEmail      = Request["EmailCts_" + i.ToString()].ToString();
                infoCts.TransactionBy  = "CRM";
                infoCts.Reason         = Request["NotesManagerConsulant"].ToString();
                infoCts.OtherInfo      = "";
                infoCts.Time           = DateTime.Now.ToString();
                infoCts.DisableWarning = true;

                if (forms.Get("FeeEdu_" + i.ToString()).ToInt32() > forms.Get("FeeEduChange_" + i.ToString()).ToInt32())
                {
                    int feeEdu       = forms.Get("FeeEdu_" + i.ToString()).ToInt32();
                    int feeEduChange = forms.Get("FeeEduChange_" + i.ToString()).ToInt32();
                    int feeReturn    = forms.Get("FeeReturn_" + i.ToString()).ToInt32();

                    infoCts.Value = (forms.Get("FeeEdu_" + i.ToString()).ToInt32()
                                     - forms.Get("FeeEduChange_" + i.ToString()).ToInt32()
                                     - forms.Get("FeeReturn_" + i.ToString()).ToInt32()).ToString();
                    if (infoCts.Value != "0")
                    {
                        listDealSesssion.pricing.Add(infoCts);
                    }
                }
                else if (forms.Get("FeeEdu_" + i.ToString()).ToInt32() < forms.Get("FeeEduChange_" + i.ToString()).ToInt32())
                {
                    infoCts.Value = (forms.Get("FeeEduChange_" + i.ToString()).ToInt32()
                                     - forms.Get("FeeEdu_" + i.ToString()).ToInt32()
                                     - forms.Get("FeeReturn_" + i.ToString()).ToInt32()).ToString();
                    listDealSesssion.deposit.Add(infoCts);
                }
                else
                {
                    //nothing
                }

                if (forms.Get("FeeReturn_" + i.ToString()).ToInt32() > 0)
                {
                    //tranfer
                    ContactInfoMoneyTranfer infoCtsTranfer = new ContactInfoMoneyTranfer();

                    infoCtsTranfer.ContactId      = Request["CodeCts_" + i.ToString()].ToString();
                    infoCtsTranfer.Value          = Request["NameCts_" + i.ToString()].ToString();
                    infoCtsTranfer.UserPhone      = forms.Get("MobileCts_" + i.ToString()).ToString();
                    infoCtsTranfer.UserEmail      = Request["EmailCts_" + i.ToString()].ToString();
                    infoCtsTranfer.TransactionBy  = "CRM";
                    infoCtsTranfer.Reason         = Request["NotesManagerConsulant"].ToString();
                    infoCtsTranfer.OtherInfo      = "";
                    infoCtsTranfer.Time           = DateTime.Now.ToString();
                    infoCtsTranfer.DisableWarning = true;

                    infoCtsTranfer.Value = forms.Get("FeeReturn_" + i.ToString()).ToString();
                    listDealSesssion.transfer.Add(infoCtsTranfer);

                    //balance
                    ContactInfoMoneyBalance infoCtsBalance = new ContactInfoMoneyBalance();

                    infoCtsBalance.ContactId      = Request["CodeCts_" + i.ToString()].ToString();
                    infoCtsBalance.Value          = Request["NameCts_" + i.ToString()].ToString();
                    infoCtsBalance.UserPhone      = forms.Get("MobileCts_" + i.ToString()).ToString();
                    infoCtsBalance.UserEmail      = Request["EmailCts_" + i.ToString()].ToString();
                    infoCtsBalance.Type           = "-1";
                    infoCtsBalance.BillNumber     = "0";
                    infoCtsBalance.TransactionBy  = "CRM";
                    infoCtsBalance.Reason         = Request["NotesManagerConsulant"].ToString();
                    infoCtsBalance.OtherInfo      = "";
                    infoCtsBalance.Time           = DateTime.Now.ToString();
                    infoCtsBalance.DisableWarning = true;

                    infoCtsBalance.Value = forms.Get("FeeReturn_" + i.ToString()).ToString();
                    listDealSesssion.balance.Add(infoCtsBalance);
                }
            }

            JsonResult retVal = new JsonResult()
            {
                Data = listDealSesssion, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
            string sRetVal = JsonConvert.SerializeObject(retVal.Data);

            //===============Goi API LocMX =============//

            string username       = "******";
            string password       = "******";
            string linkApiPayment = ConfigurationManager.AppSettings["LinkAPIPayment"].ToString();

            var client = new RestClient(linkApiPayment);

            client.Authenticator = new HttpBasicAuthenticator(username, password);
            var request = new RestRequest("Tcoin/CrmTransactionBatch", Method.POST);

            request.AddHeader("Accept", "application/json");

            request.AddParameter("key", "6WxDCFTjlgjH6L6YLA03LNW1JbJbCZGCLHa0DIXT");
            request.AddParameter("data", sRetVal);
            request.JsonSerializer.ContentType = "application/json; charset=utf-8";

            IRestResponse           response = client.Execute(request);
            string                  s        = response.Content;
            ReturnApiCallFixedMoney output   = JsonConvert.DeserializeObject <ReturnApiCallFixedMoney>(s);

            //Neu goi thanh cong tao log save lai giao dich trong bang LogFixedMoney
            if (output.status_code == "DONE_ALL")
            {
                SqlTransaction tran = null;
                try
                {
                    string        conString = getNewConnection;
                    SqlConnection conn      = new SqlConnection(conString);
                    conn.Open();
                    tran = conn.BeginTransaction();

                    //Update FeeEdu, PackageSale
                    for (int i = 1; i <= valueRow; i++)
                    {
                        var sCode   = Request["CodeCts_" + i.ToString()].ToString();
                        var sFeeEdu = Request["FeeEduChange_" + i.ToString()].ToInt32();
                        ContactLevelInfoRepository.Update_FeeEdu_PackagePriceSale(sCode, sFeeEdu);
                    }
                    var log = new LogFixedMoney
                    {
                        Description         = sRetVal,
                        Notes               = notes,
                        UserConsulantCreate = userTVTS.UserName,
                        CreateDate          = DateTime.Now
                    };

                    LogFixMoneyRepository.Create(log, tran);

                    int idMax = GetIdentity("LogFixMoney", conn, tran); //lay ID max trong bang LogFixMoney

                    foreach (var a in listDealSesssion.pricing)
                    {
                        var logmoney_pricing = new LogsMoneyInfo
                        {
                            TienHVNop       = a.Value.ToInt32(),
                            TienBanGoi      = 0, //hoi lai
                            NoteChuyenKhoan = a.Reason,
                            NguoiTao        = a.UserName,
                            NgayThucThu     = DateTime.Now,
                            KieuThanhToan   = 0,
                            DiaPhuong       = 1,
                            CreateDate      = DateTime.Now,
                            ContactId       = 0,
                            Code            = a.ContactId,
                            ChuDuToan       = 0,
                            TrangThai       = true,
                            HistoryId       = 0,
                            IdFixMoney      = idMax
                        };
                        MoneyLogsRepository.Create(logmoney_pricing, tran);
                    }

                    foreach (var a in listDealSesssion.deposit)
                    {
                        var logmoney_deposit = new LogsMoneyInfo
                        {
                            TienHVNop       = a.Value.ToInt32(),
                            TienBanGoi      = 0, //hoi lai
                            NoteChuyenKhoan = a.Reason,
                            NguoiTao        = a.UserName,
                            NgayThucThu     = DateTime.Now,
                            KieuThanhToan   = 0,
                            DiaPhuong       = 1,
                            CreateDate      = DateTime.Now,
                            ContactId       = 0,
                            Code            = a.ContactId,
                            ChuDuToan       = 0,
                            TrangThai       = true,
                            HistoryId       = 0,
                            IdFixMoney      = idMax
                        };
                        MoneyLogsRepository.Create(logmoney_deposit, tran);
                    }

                    foreach (var a in listDealSesssion.transfer)
                    {
                        var logmoney_transfer = new LogsMoneyInfo
                        {
                            TienHVNop       = a.Value.ToInt32(),
                            TienBanGoi      = 0, //hoi lai
                            NoteChuyenKhoan = a.Reason,
                            NguoiTao        = "",
                            NgayThucThu     = DateTime.Now,
                            KieuThanhToan   = 0,
                            DiaPhuong       = 1,
                            CreateDate      = DateTime.Now,
                            ContactId       = 0,
                            Code            = a.ContactId,
                            ChuDuToan       = 0,
                            TrangThai       = true,
                            HistoryId       = 0,
                            IdFixMoney      = idMax
                        };
                        MoneyLogsRepository.Create(logmoney_transfer, tran);
                    }
                    tran.Commit();

                    ViewBag.Message = "Giao dịch chuyển tiền thành công";

                    return(FixedMoneyManagerConsulant());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " " + ex.Data);
                    if (tran != null)
                    {
                        tran.Rollback();
                    }
                    ViewBag.Message = "Có lỗi xảy ra, vui lòng thực hiện lại";
                    return(FixedMoneyManagerConsulant());
                }
            }
            else
            {
                //return lỗi ko thành công.
                ViewBag.Message = "Giao dịch chuyển tiền không thành công: " + output.msg;
                return(FixedMoneyManagerConsulant());
            }
        }