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()); }