public ActionResult CreateHotLine() { var model = new ContactAddModel(); return View(model); }
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 { ViewBag.Message = "Hệ thống cache bị lỗi, vui lòng thử lại sau"; return CreateHotLine(); } 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), }; //int a = ContactRepository.check_old_db(entity); //if (a > 0) //{ // ViewBag.Message = "Contact trùng với database cũ"; // return CreateHotLine(); //} 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) { // Redis StoreData.LoadRedis(entity.Id); // Message ViewBag.Message = "Thêm mới contact thành công"; } 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 { ViewBag.Message = "Thêm mới contact bị exception, vui lòng thử lại sau"; //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 entity.Id = contactInfo.Id; entity.TypeId = contactInfo.TypeId; ContactRepository.ContactUpdateDuplicate(entity.Id, entity.TypeId, entity.StatusId); // 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(); }
public ActionResult CreateTvts(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 { ViewBag.Message = "Hệ thống cache bị lỗi, vui lòng thử lại sau"; 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), StatusMapConsultantId = 1, StatusCareConsultantId = 1, HandoverConsultantDate = DateTime.Now, AppointmentConsultantDate = DateTime.Now, StatusId = (int)StatusType.HandoverConsultant, UserConsultantId = UserContext.GetCurrentUser().UserID, }; //int a = ContactRepository.check_old_db(entity); //if (a > 0) //{ // ViewBag.Message = "Contact trùng với database cũ"; // return CreateHotLine(); //} 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 { ViewBag.Message = "Thêm mới contact bị exception, vui lòng thử lại sau"; //Redis StoreData.DeleteRedis(model.ContactInfo.Mobile1, model.ContactInfo.Mobile2, string.Empty, model.ContactInfo.Email, model.ContactInfo.Email2); } } else { // 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(); } } } return CreateTvts(); }