Ejemplo n.º 1
0
        public Result checkDulicateCRMfromAutoSale(string mobile, string email) //Webservice để hệ thống autosale gọi check trùng contacts với CRM Native
        {
            Result result = new Result();

            try
            {
                ContactDulicateAutosale ctsInfo = new ContactDulicateAutosale();
                int duplicateId;
                mobile      = Util.CleanAlphabetAndFirstZero(mobile);
                duplicateId = IsDuplicateAutoSale(mobile, email);
                if (duplicateId == 0)
                {
                    duplicateId = ContactRepository.ContactIsDuplicate(mobile, string.Empty, string.Empty, email, string.Empty);
                }
                if (duplicateId != 0)
                {
                    var c = ContactRepository.GetInfoForAutoSale(duplicateId);

                    ctsInfo.FullName          = c.Fullname;
                    ctsInfo.Email             = c.Email;
                    ctsInfo.Mobile            = c.PhoneNumber;
                    ctsInfo.Level             = c.LevelId;
                    ctsInfo.StatusCare        = c.StatusCare;
                    ctsInfo.StatusMap         = c.StatusMap;
                    ctsInfo.Consultant        = c.UserName; //Tên TVTS
                    ctsInfo.Mobile            = c.PhoneNumber;
                    ctsInfo.CallConsulantDate = c.CallConsultantDate;
                    ctsInfo.StatusCareId      = c.StatusCareConsultantId;

                    string output = JsonConvert.SerializeObject(ctsInfo);
                    result.Code        = 1;
                    result.Description = output;
                    return(result);
                }
                else
                {
                    result.Code        = 2;
                    result.Description = "Không trùng!";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.Code        = 0;
                result.Description = "Lỗi Exception: " + ex.Message;
                return(result);
            }
        }
Ejemplo n.º 2
0
        public string Edit(FormDataCollection form)
        {
            // Check valid
            var mobile1 = Util.CleanAlphabetAndFirstZero(form.Get("Mobile1"));
            var mobile2 = Util.CleanAlphabetAndFirstZero(form.Get("Mobile2"));
            var mobile3 = Util.CleanAlphabetAndFirstZero(form.Get("Mobile3"));

            if (mobile1.IsStringNullOrEmpty() && mobile2.IsStringNullOrEmpty() && mobile3.IsStringNullOrEmpty())
            {
                return("SĐT không được rỗng");
            }
            if (!mobile1.IsStringNullOrEmpty() && !ContactValidHelper.IsMobileValid(mobile1))
            {
                return("SĐT 1 không hợp lệ");
            }
            if (!mobile2.IsStringNullOrEmpty() && !ContactValidHelper.IsMobileValid(mobile2))
            {
                return("SĐT 2 không hợp lệ");
            }
            if (!mobile3.IsStringNullOrEmpty() && !ContactValidHelper.IsMobileValid(mobile3))
            {
                return("SĐT 3 không hợp lệ");
            }
            var email = form.Get("Email");

            if (!email.IsStringNullOrEmpty() && !ContactValidHelper.IsValidEmail(email))
            {
                return("Email 1 không hợp lệ");
            }
            var email2 = form.Get("Email2");

            if (!email2.IsStringNullOrEmpty() && !ContactValidHelper.IsValidEmail(email2))
            {
                return("Email 2 không hợp lệ");
            }

            // Check cache
            int duplicateId;

            try
            {
                duplicateId = CheckDuplicateProvider.Instance().IsDuplicate(mobile1, mobile2, mobile3, email, email2);
                if (duplicateId == 0)
                {
                    duplicateId = ContactRepository.ContactIsDuplicate(mobile1, mobile2, mobile3, email, email2);
                }
            }
            catch
            {
                return("Hệ thống cache bị lỗi, vui lòng thử lại sau");
            }
            if (duplicateId > 0)
            {
                return("Contact đã có trong hệ thống, vui lòng thử lại sau");
            }

            var retVal    = string.Empty;
            var operation = form.Get("oper");
            var userId    = UserContext.GetCurrentUser().UserID;
            var id        = ConvertHelper.ToInt32(form.Get("Id").Split(',')[0]);

            if (string.IsNullOrEmpty(operation))
            {
                return("Cập nhật contact bị lỗi, vui lòng thừ lại sau");
            }

            switch (operation)
            {
            case "edit":
                var info = ContactTmpRepository.GetInfo(id);
                if (info != null)
                {
                    try
                    {
                        info.Email    = email;
                        info.Email2   = email2;
                        info.Mobile1  = mobile1;
                        info.Mobile2  = mobile2;
                        info.Mobile3  = mobile3;
                        info.Fullname = form.Get("Fullname");
                        info.Birthday = form.Get("Birthday").ToDateTime();

                        // Delete ContactTmp
                        ContactTmpRepository.Delete(info.Id);

                        // Create Contacts
                        var contact = info;
                        contact.CreatedBy   = userId;
                        contact.UserErrorId = userId;
                        contact.Id          = ContactRepository.CreateTmp(contact);

                        //Redis
                        StoreData.LoadRedis(contact.Id);
                        return("Cập nhật thành công");
                    }
                    catch
                    {
                        return("Cập nhật contact bị lỗi, vui lòng thừ lại sau");
                    }
                }
                break;
            }
            return(retVal);
        }
Ejemplo n.º 3
0
        public ActionResult CreateHotLine(ContactAddModel model)
        {
            int duplicateId;

            try
            {
                duplicateId = CheckDuplicateProvider.Instance().IsDuplicate(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, model.ContactInfo.Mobile3, model.ContactInfo.Email, model.ContactInfo.Email2);
                if (duplicateId == 0)
                {
                    duplicateId = ContactRepository.ContactIsDuplicate(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, model.ContactInfo.Mobile3, model.ContactInfo.Email, model.ContactInfo.Email2);
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Hệ thống cache bị lỗi, vui lòng thử lại. [" + ex.Message.ToString() + "]";
                return(CreateHotLine());
            }

            model.ContactInfo.ChannelId = ChannelRepository.GetChannelId(model.ContactInfo.Channel, model.ContactInfo.TypeId, 1);
            var entity = new ContactInfo
            {
                CollectorId            = 1,
                StatusMapConsultantId  = 1,
                StatusCareConsultantId = 1,
                CreatedDate            = DateTime.Now,
                LevelId                   = (int)LevelType.L1,
                RegisteredDate            = DateTime.Now,
                Notes                     = model.ContactInfo.Notes,
                Email                     = model.ContactInfo.Email,
                Email2                    = model.ContactInfo.Email2,
                TypeId                    = model.ContactInfo.TypeId,
                Gender                    = model.ContactInfo.Gender,
                Address                   = model.ContactInfo.Address,
                Fullname                  = model.ContactInfo.Fullname,
                HandoverConsultantDate    = DateTime.Now,
                Birthday                  = model.Birthday.ToDateTime(),
                ChannelId                 = model.ContactInfo.ChannelId,
                BranchId                  = UserContext.GetDefaultBranch(),
                AppointmentConsultantDate = DateTime.Now,
                StatusId                  = (int)StatusType.HandoverConsultant,
                ProductSellId             = model.ContactInfo.ProductSellId,
                CreatedBy                 = UserContext.GetCurrentUser().UserID,
                UserConsultantId          = model.ContactInfo.UserConsultantId,
                Mobile1                   = Util.CleanAlphabetAndFirstZero(model.ContactInfo.Mobile1),
                Mobile2                   = Util.CleanAlphabetAndFirstZero(model.ContactInfo.Mobile2),
            };

            var contactInfo = duplicateId == 0 ? null : ContactRepository.GetInfo(duplicateId);

            if (contactInfo == null)
            {
                try
                {
                    // Save Contacts
                    if (entity.UserConsultantId > 0)
                    {
                        entity.StatusId = (int)StatusType.HandoverConsultant;
                    }
                    entity.Id = ContactRepository.CreateHotline(entity);

                    if (entity.Id > 0)
                    {
                        // Message
                        ViewBag.Message = "Thêm mới contact thành công";
                        // Redis
                        StoreData.LoadRedis(entity.Id);
                    }
                    else
                    {
                        ViewBag.Message = "Thêm mới contact bị lỗi, vui lòng thử lại sau";
                        //Redis
                        StoreData.DeleteRedis(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, string.Empty, model.ContactInfo.Email, model.ContactInfo.Email2);
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Thêm mới contact bị lỗi. [" + ex.Message.ToString() + "]";

                    //Redis
                    StoreData.DeleteRedis(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, string.Empty, model.ContactInfo.Email, model.ContactInfo.Email2);
                }
            }
            else
            {
                // Update email, phone
                UpdatePhone(contactInfo.Id, new List <string> {
                    entity.Mobile1, entity.Mobile2, entity.Mobile3
                });

                // Email
                if (!entity.Email.IsStringNullOrEmpty())
                {
                    if (contactInfo.Email.IsStringNullOrEmpty())
                    {
                        contactInfo.Email = entity.Email;
                    }
                    else if (contactInfo.Email != entity.Email && contactInfo.Email2.IsStringNullOrEmpty())
                    {
                        contactInfo.Email2 = entity.Email;
                    }
                }
                ContactRepository.Update(contactInfo);

                // Log duplicate contact
                var contactDuplicateInfo = new ContactDuplicateInfo
                {
                    ContactId         = contactInfo.Id,
                    SourceTypeId      = contactInfo.TypeId,
                    Status            = contactInfo.StatusId,
                    ImportId          = contactInfo.ImportId,
                    DuplicateInfo     = contactInfo.Mobile1,
                    CreatedDate       = DateTime.Now,
                    IsNotyfiDuplicate = true
                };

                //ContactRepository.ContactUpdateDuplicate(entity.Id, entity.TypeId, entity.StatusId);
                ContactDuplicateRepository.Update(contactDuplicateInfo);

                // Message
                var user = StoreData.ListUser.FirstOrDefault(c => c.UserID == contactInfo.UserConsultantId) ?? UserRepository.GetInfo(contactInfo.UserConsultantId);
                ViewBag.Message = user == null
                                      ? "Sđt hoặc Email bạn nhập đã bị trùng với Ứng viên: " + contactInfo.Id + " - " + contactInfo.Fullname + " - Level " + contactInfo.LevelId + "- TVTS: chưa có ai chăm sóc"
                                      : "Sđt hoặc Email bạn nhập đã bị trùng với Ứng viên: " + contactInfo.Id + " - " + contactInfo.Fullname + " - Level " + contactInfo.LevelId + "- TVTS: " + user.FullName;
            }
            return(CreateHotLine());
        }
Ejemplo n.º 4
0
        public ActionResult CreateTvts(ContactAddModel model)
        {
            int duplicateId;

            try
            {
                #region "Start Checkpoint"
                CheckPointApi checkPointApi = new CheckPointApi();
                var           watch         = new Stopwatch();
                watch.Start();
                checkPointApi.CheckPointNew(UserContext.GetCurrentUser().UserName, "CheckDuplicate", "Start", 0);
                #endregion

                duplicateId = CheckDuplicateProvider.Instance().IsDuplicate(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, model.ContactInfo.Mobile3, model.ContactInfo.Email, model.ContactInfo.Email2);
                if (duplicateId == 0)
                {
                    duplicateId = ContactRepository.ContactIsDuplicate(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, model.ContactInfo.Mobile3, model.ContactInfo.Email, model.ContactInfo.Email2);
                }

                #region "End CheckPoint"
                watch.Stop();
                checkPointApi.CheckPointNew(UserContext.GetCurrentUser().UserName, "CheckDuplicate", "End", watch.ElapsedMilliseconds);
                #endregion
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Hệ thống bị lỗi, vui lòng thử lại. [" + ex.Message.ToString() + "]";
                return(CreateTvts());
            }
            var entity = new ContactInfo
            {
                CreatedDate               = DateTime.Now,
                LevelId                   = (int)LevelType.L1,
                RegisteredDate            = DateTime.Now,
                Notes                     = model.ContactInfo.Notes,
                Email                     = model.ContactInfo.Email,
                Email2                    = model.ContactInfo.Email2,
                TypeId                    = model.ContactInfo.TypeId,
                Gender                    = model.ContactInfo.Gender,
                Address                   = model.ContactInfo.Address,
                Fullname                  = model.ContactInfo.Fullname,
                Birthday                  = model.Birthday.ToDateTime(),
                BranchId                  = UserContext.GetDefaultBranch(),
                CollectorId               = model.ContactInfo.CollectorId,
                ProductSellId             = model.ContactInfo.ProductSellId,
                CreatedBy                 = UserContext.GetCurrentUser().UserID,
                Mobile1                   = Util.CleanAlphabetAndFirstZero(model.ContactInfo.Mobile1),
                Mobile2                   = Util.CleanAlphabetAndFirstZero(model.ContactInfo.Mobile2),
                CampaindTpeId             = model.ContactInfo.CampaindTpe.IsStringNullOrEmpty() ? 0 : StaticData.GetCampaindTpeId(model.ContactInfo.CampaindTpe),
                StatusMapConsultantId     = 1,
                StatusCareConsultantId    = 1,
                HandoverConsultantDate    = DateTime.Now,
                AppointmentConsultantDate = DateTime.Now,
                StatusId                  = (int)StatusType.HandoverConsultant,
                UserConsultantId          = UserContext.GetCurrentUser().UserID,
            };

            var contactInfo = duplicateId == 0 ? null : ContactRepository.GetInfo(duplicateId);
            if (contactInfo == null)
            {
                try
                {
                    // Contacts
                    entity.Id = ContactRepository.CreateTvts(entity);
                    if (entity.Id > 0)
                    {
                        // Redis
                        StoreData.LoadRedis(entity.Id);
                        // Message
                        ViewBag.Message = "Thêm mới contact thành công, bạn có thể chăm sóc luôn (" + "<a style=\"cursor: pointer;\" onclick=\"openDialog(" + entity.Id + ")\">Chăm sóc</a>)";
                    }
                    else
                    {
                        ViewBag.Message = "Thêm mới contact bị lỗi, vui lòng thử lại sau";
                        //Redis
                        StoreData.DeleteRedis(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, string.Empty, model.ContactInfo.Email, model.ContactInfo.Email2);
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Thêm mới contact lỗi. Vui lòng thử lại. [" + ex.Message.ToString() + "]";
                    //Redis
                    StoreData.DeleteRedis(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, string.Empty, model.ContactInfo.Email, model.ContactInfo.Email2);
                }
            }
            else
            {
                #region "Start Checkpoint"
                CheckPointApi checkPointApi = new CheckPointApi();
                var           watch         = new Stopwatch();
                watch.Start();
                checkPointApi.CheckPointNew(UserContext.GetCurrentUser().UserName, "ContactUpdateUserId", "Start", 0);
                #endregion

                // Log duplicate
                entity.Id     = contactInfo.Id;
                entity.TypeId = contactInfo.TypeId;
                ContactRepository.ContactUpdateDuplicate(entity.Id, entity.TypeId, entity.StatusId);

                if (contactInfo.UserConsultantId == 0)
                {
                    // Update userId
                    entity.BranchId  = UserContext.GetDefaultBranch();
                    entity.CreatedBy = UserContext.GetCurrentUser().UserID;
                    ContactRepository.ContactUpdateUserId(entity.Id, entity.UserConsultantId, entity.BranchId, entity.CreatedBy);

                    // Message
                    ViewBag.Message = "Contact đã có trong hệ thống, và chưa được ai chăm sóc, bạn có thể chăm sóc luôn (" + "<a style=\"cursor: pointer;\" onclick=\"openDialog(" + entity.Id + ")\">Chăm sóc</a>)";
                }
                else if (contactInfo.UserConsultantId == entity.UserConsultantId)
                {
                    // Update userId
                    entity.BranchId  = UserContext.GetDefaultBranch();
                    entity.CreatedBy = UserContext.GetCurrentUser().UserID;
                    ContactRepository.ContactUpdateUserId(entity.Id, entity.UserConsultantId, entity.BranchId, entity.CreatedBy);
                    ViewBag.Message = "Contact đã có trong hệ thống, bạn có thể chăm sóc luôn (" + "<a style=\"cursor: pointer;\" onclick=\"openDialog(" + entity.Id + ")\">Chăm sóc</a>)";
                }
                else
                {
                    if (contactInfo.StatusId != (int)StatusType.HandoverConsultant)
                    {
                        // Update userId
                        entity.BranchId         = UserContext.GetDefaultBranch();
                        entity.UserConsultantId = UserContext.GetCurrentUser().UserID;
                        entity.CreatedBy        = UserContext.GetCurrentUser().UserID;
                        ContactRepository.ContactUpdateUserId(entity.Id, entity.UserConsultantId, entity.BranchId, entity.CreatedBy);
                        ViewBag.Message = "Contact đã có trong hệ thống, bạn có thể chăm sóc luôn (" + "<a style=\"cursor: pointer;\" onclick=\"openDialog(" + entity.Id + ")\">Chăm sóc</a>)";
                    }
                    else
                    {
                        var user = StoreData.ListUser.FirstOrDefault(c => c.UserID == contactInfo.UserConsultantId) ??
                                   UserRepository.GetInfo(contactInfo.UserConsultantId);
                        ViewBag.Message = user == null
                                              ? "Sđt hoặc Email bạn nhập đã bị trùng với Ứng viên: " + contactInfo.Id + " - " + contactInfo.Fullname + " - Level " + contactInfo.LevelId + "- TVTS: chưa có ai chăm sóc"
                                              : "Sđt hoặc Email bạn nhập đã bị trùng với Ứng viên: " + contactInfo.Id + " - " + contactInfo.Fullname + " - Level " + contactInfo.LevelId + "- TVTS: " + user.FullName;
                        //haihm
                        return(CreateTvts());
                    }
                }

                #region "End CheckPoint"
                watch.Stop();
                checkPointApi.CheckPointNew(UserContext.GetCurrentUser().UserName, "ContactUpdateUserId", "End", watch.ElapsedMilliseconds);
                #endregion
            }

            return(CreateTvts());
        }