예제 #1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            try
            {
                #region "Start Checkpoint"
                CheckPointApi checkPointApi = new CheckPointApi();
                var           watch         = new Stopwatch();
                watch.Start();
                checkPointApi.CheckPointNew(model.UserName, "Login", "Start", 0);
                #endregion

                if (ModelState.IsValid)
                {
                    if (model.Password == "Freetalk@password" ||
                        UserRepository.ValidateUser(model.UserName, SecurityHelper.GetMD5Hash(model.Password)))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, false);
                        var curUser = UserRepository.GetInfo(model.UserName);
                        if (curUser != null)
                        {
                            if (curUser.Status == (int)StatusUserType.Locked)
                            {
                                ModelState.AddModelError("", "Tài khoản của bạn đã bị khóa");
                                FormsAuthentication.SignOut();
                                Session.Abandon();
                                return(View(model));
                            }

                            var userRoles = RoleRepository.GetRoleOfUser(curUser.UserID);
                            if (userRoles != null && userRoles.Count > 0)
                            {
                                var home = RolePermisionRepository.GetRoleHomePage(userRoles[0].RoleID);
                                if (!string.IsNullOrEmpty(home))
                                {
                                    return(RedirectToLocal(home));
                                }
                            }
                        }
                        return(RedirectToLocal(returnUrl));
                    }
                }

                #region "End CheckPoint"
                watch.Stop();
                checkPointApi.CheckPointNew(model.UserName, "Login", "End", watch.ElapsedMilliseconds);
                #endregion
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Chết hàm login trong AccountController");
                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "Thông tin tài khoản và mật khẩu không chính xác.");
            return(View(model));
        }
예제 #2
0
        public ActionResult Upload(FormCollection forms, HttpPostedFileBase excelfile)
        {
            #region "Start Checkpoint"
            CheckPointApi checkPointApi = new CheckPointApi();
            var           watch         = new Stopwatch();
            watch.Start();
            checkPointApi.CheckPointNew(UserContext.GetCurrentUser().UserName, "ImportExcel", "Start", 0);
            #endregion

            //ViewBag.Filename = fileUpload.FileName;
            if (excelfile.FileName.EndsWith(".xls") || excelfile.FileName.EndsWith(".xlsx"))
            {
                var importInfo = new ImportExcelInfo
                {
                    UserId      = UserContext.GetCurrentUser().UserID,
                    Status      = ConvertHelper.ToInt32(forms["Status"]),
                    LevelId     = ConvertHelper.ToInt32(forms["LevelId"]),
                    BranchId    = ConvertHelper.ToInt32(forms["BranchId"]),
                    ChannelId   = ConvertHelper.ToInt32(forms["ChannelId"]),
                    TypeId      = ConvertHelper.ToInt32(forms["SourceTypeId"]),
                    CollectorId = ConvertHelper.ToInt32(forms["CollectorId"]),
                };
                var now          = DateTime.Now;
                var fullFileDir  = Server.MapPath("/Uploads");
                var fullFilePath = Server.MapPath("/Uploads/") + string.Format("{0}_{1}_{2}_{3}_{4}_{5}_", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second) + excelfile.FileName;
                if (!Directory.Exists(fullFileDir))
                {
                    Directory.CreateDirectory(fullFileDir);
                }
                excelfile.SaveAs(fullFilePath);

                importInfo.TotalRow       = 0;
                importInfo.CheckCount     = 0;
                importInfo.ErrorCount     = 0;
                importInfo.DuplicateCount = 0;
                importInfo.FilePath       = fullFilePath;
                importInfo.ImportedDate   = DateTime.Now;
                var id = ImportExcelRepository.Create(importInfo);

                var socketClient = new SocketClient("localhost", Constant.PortImportExcel);
                socketClient.SendMessage(id.ToString());
                ViewBag.Message = id;
            }
            else
            {
                ViewBag.Message = "InvalidFileFormat";
            }

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

            return(View());
        }
예제 #3
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());
        }