public ActionResult UserScrubsGrid()
        {
            var Leads = leadService.GetLeadTypes().ToList();
            List <UserScrubsGridModel> retData = new List <UserScrubsGridModel>();
            var userScrubs = userScrubService.GetScrubsByUserId(this.CurrentLoggedInUser.Id);
            int iCount     = 0;

            foreach (var u in userScrubs)
            {
                iCount += 1;
                List <int> leadTypes       = JsonConvert.DeserializeObject <List <DropDownModel> >(u.LeadTypeIds).Select(x => x.Id).ToList();
                string     InputExtensions = u.InputFilePath.Split('.')[1];
                retData.Add(new UserScrubsGridModel()
                {
                    Sno          = iCount,
                    ScrubCredits = LeadsHelpers.ToUsNumberFormat(u.ScrubCredits),
                    CreatedAt    = u.CreatedDate.ToString("dd-MMM-yyyy hh:mm:ss tt"),
                    LeadType     = String.Join(",", Leads.Where(x => leadTypes.Contains(x.Id)).Select(x => x.Name).ToList()),
                    Matched      = "Matched- " + u.MatchedCount + " <a href='" + u.MatchedPath + ".csv' style='cursor:pointer' download='Matched-" + u.Id + ".csv'><i class='fa fa-download' ></i></a><br>" + "Clean- " + u.UnMatchedCount + " <a href='" + u.UnMatchedPath + ".csv' style='cursor:pointer' download='UnMatched-" + u.Id + ".csv'><i class='fa fa-download' ></i></a>",
                    Duration     = u.Duration,
                    InputFile    = "Input File  <a href='" + u.InputFilePath + "' style='cursor:pointer' download='InputFile-" + u.Id + "." + InputExtensions + "'><i class='fa fa-download' ></i></a>",
                });
            }
            var jsonData = new { data = from emp in retData select emp };

            return(new JsonResult()
            {
                Data = jsonData,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                MaxJsonLength = Int32.MaxValue
            });
        }
Exemple #2
0
        public ActionResult CreditPackageGrid()
        {
            List <CreditPackageViewModel> retData = new List <CreditPackageViewModel>();
            var leadTypesList = creditPackageService.GetAllCreditPackages().OrderBy(x => x.PackageName).ToList();
            int iCount        = 0;

            foreach (var l in leadTypesList)
            {
                iCount += 1;
                retData.Add(new CreditPackageViewModel()
                {
                    Id          = l.Id,
                    SNo         = iCount,
                    Status      = l.IsActive == true ? "Active" : "InActive",
                    CreatedDate = l.CreatedAt.ToString("dd-MMM-yyyy hh:mm:ss tt"),
                    IsActive    = l.IsActive,
                    PackageName = l.PackageName,
                    Credits     = l.Credits,
                    CreditsStr  = LeadsHelpers.ToUsNumberFormat(l.Credits),
                    Price       = l.Price,
                    EditBtn     = "<button type='button' class='btn btn-primary m-b-10 btnedit btn-sm' data-id='" + l.Id + "' data-packagename='" + l.PackageName + "' data-credits='" + l.Credits + "' data-price='" + l.Price + "' data-status='" + l.IsActive + "' data-id='" + l.Id + "'><i class='fa fa-pencil-square-o'></i> Edit</button>"
                });
            }
            var jsonData = new { data = from emp in retData select emp };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetUserCreditsDetails()
        {
            var usedCredits      = userScrubService.GetScrubsByUserId(this.CurrentLoggedInUser.Id).Sum(x => x.ScrubCredits);
            var userTotalCredits = this.CurrentLoggedInUser.CreditScore;
            var remainingCredits = userTotalCredits - usedCredits;

            return(Json(new
            {
                remainingCredits = LeadsHelpers.ToUsNumberFormat(remainingCredits),
                totalCredits = LeadsHelpers.ToUsNumberFormat(userTotalCredits),
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult UserCreditLogGrid()
        {
            List <UserCreditLogGridViewModel> retData = new List <UserCreditLogGridViewModel>();
            var userCreditLogs = userCreditLogsService.GetAllUserCreditLogs().Where(x => x.UserId == CurrentLoggedInUser.Id).ToList();
            int iCount         = 0;

            foreach (var u in userCreditLogs)
            {
                iCount += 1;
                retData.Add(new UserCreditLogGridViewModel()
                {
                    SNo                = iCount,
                    Id                 = u.Id,
                    Date               = u.CreatedAt.ToString("dd-MMM-yyyy hh:mm:ss tt"),
                    CreatedAt          = u.CreatedAt,
                    Credits            = LeadsHelpers.ToUsNumberFormat(u.Credits),
                    DisCountPercentage = u.DiscountPercentage.ToString(),
                    AmountPaid         = Math.Round(u.FinalAmount, 2).ToString(),
                    PackageName        = creditPackageService.GetAllCreditPackages().FirstOrDefault(x => x.Id == u.PackageId).PackageName
                });
            }
            var usersRefered       = userService.GetUsers().Where(x => x.ReferedUserId.HasValue && x.ReferedUserId.Value == CurrentLoggedInUser.Id).ToList();
            var referalCreditsList = userCreditLogsService.GetAllUserCreditLogs().ToList().Where(x => usersRefered.Select(y => y.Id).Contains(x.UserId));

            foreach (var u in referalCreditsList)
            {
                iCount += 1;
                var thisUser = usersRefered.Where(x => x.Id == u.UserId).FirstOrDefault();
                retData.Add(new UserCreditLogGridViewModel()
                {
                    SNo                = iCount,
                    Id                 = u.Id,
                    Date               = u.CreatedAt.ToString("dd-MMM-yyyy hh:mm:ss tt"),
                    CreatedAt          = u.CreatedAt,
                    Credits            = LeadsHelpers.ToUsNumberFormat(u.ReferalUserCredits),
                    DisCountPercentage = "-",
                    AmountPaid         = "-",
                    PackageName        = "Referral Bonus From " + thisUser.Name
                });
            }

            retData = retData.OrderByDescending(x => x.CreatedAt).ToList();
            var jsonData = new { data = from emp in retData select emp };

            return(new JsonResult()
            {
                Data = jsonData,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                MaxJsonLength = Int32.MaxValue
            });
        }
Exemple #5
0
        public ActionResult UsersGrid()
        {
            var userScrubLogs = userScrubService.GetAllUserScrubs().ToList();
            List <UserGridViewModel> retData = new List <UserGridViewModel>();

            retData = userService.GetUsers().Where(x => x.IsAdmin == false).ToList().Select(x => new UserGridViewModel
            {
                Id                 = x.Id,
                Name               = x.Name,
                Email              = x.Email,
                Phone              = x.Phone,
                Password           = x.Password,
                CreatedAt          = x.CreatedAt.ToString("dd-MMM-yyyy hh:mm:ss tt"),
                CreditScore        = x.CreditScore,
                Status             = userService.GetStatusById(x.StatusId),
                ModifiedAt         = x.ModifiedAt.HasValue?x.ModifiedAt.Value.ToString("dd-MMM-yyyy hh:mm:ss tt"):string.Empty,
                StatusId           = x.StatusId,
                ReferalCode        = x.ReferalCode,
                ReferedById        = x.ReferedUserId.HasValue ? x.ReferedUserId.Value : 0,
                DiscountPercentage = x.DiscountPercentage.HasValue?x.DiscountPercentage.Value:0
            }).ToList();
            int iCount = 0;

            foreach (var r in retData)
            {
                iCount          += 1;
                r.SNo            = iCount;
                r.CreditScoreStr = LeadsHelpers.ToUsNumberFormat(r.CreditScore - userScrubLogs.Where(x => x.UserId == r.Id).Sum(x => x.ScrubCredits));
                if (r.StatusId == 1)
                {
                    r.EditBtn = "<button type='button' class='btn btn-success m-b-10 btnapprove btn-sm' data-id='" + r.Id + "'data-discountPercentage='" + r.DiscountPercentage + "' data-score='" + r.CreditScore + "'>Approve</button>";
                }
                else if (r.StatusId == 2)
                {
                    r.EditBtn = "<button type='button' class='btn btn-danger m-b-10 btninactivate btn-sm' data-id='" + r.Id + "' data-discountPercentage='" + r.DiscountPercentage + "' data-score='" + r.CreditScore + "'>In-Activate</button> &nbsp;&nbsp;" +
                                "<button type = 'button' class='btn btn-success m-b-10 btnedit btn-sm' data-id='" + r.Id + "' data-discountPercentage='" + r.DiscountPercentage + "' data-status='" + r.StatusId + "' data-score='" + r.CreditScore + "'>Edit</button>";
                }
                else
                {
                    r.EditBtn = "<button type='button' class='btn btn-primary m-b-10 btnactivate btn-sm' data-id='" + r.Id + "' data-discountPercentage='" + r.DiscountPercentage + "' data-score='" + r.CreditScore + "'>Activate</button>&nbsp;&nbsp;"
                                + "<button type = 'button' class='btn btn-success m-b-10 btnedit btn-sm' data-id='" + r.Id + "' data-discountPercentage='" + r.DiscountPercentage + "' data-status='" + r.StatusId + "' data-score='" + r.CreditScore + "'>Edit</button>";
                }
                if (r.ReferedById != 0)
                {
                    r.RefedByUserName = userService.GetUsers().FirstOrDefault(x => x.Id == r.ReferedById).Name;
                }
            }
            var jsonData = new { data = from emp in retData select emp };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Scrubber()
        {
            ViewBag.IsFileError   = "false";
            ViewBag.CurrentUser   = this.CurrentLoggedInUser;
            ViewBag.LeadTypesList = leadService.GetLeadTypes().Where(x => x.IsActive == true).ToList().Select(x => new DropDownModel()
            {
                Name = x.Name,
                Id   = x.Id
            }).OrderBy(x => x.Name).ToList();
            var usedCredits      = userScrubService.GetScrubsByUserId(this.CurrentLoggedInUser.Id).Sum(x => x.ScrubCredits);
            var userTotalCredits = this.CurrentLoggedInUser.CreditScore;

            ViewBag.remainingCredits = LeadsHelpers.ToUsNumberFormat(userTotalCredits - usedCredits);
            ViewBag.totalCredits     = LeadsHelpers.ToUsNumberFormat(userTotalCredits);
            ViewBag.NoCredits        = false;
            return(View());
        }
Exemple #7
0
        public ActionResult UserCreditLogsGrid(DateTime date)
        {
            List <UserCreditLogGridViewModel> retData = new List <UserCreditLogGridViewModel>();
            var userCreditLogs = userCreditLogsService.GetAllUserCreditLogs().ToList().Where(x => x.CreatedAt.Date == date.Date);
            var users          = userService.GetUsers().ToList();
            int iCount         = 0;

            foreach (var u in userCreditLogs)
            {
                var    thisUser       = users.Where(x => x.Id == u.UserId).FirstOrDefault();
                string ReferalDetails = string.Empty;
                if (thisUser.ReferedUserId.HasValue && thisUser.ReferedUserId.Value > 0)
                {
                    ReferalDetails = string.Format("Referral Bonus {0} to {1}", LeadsHelpers.ToUsNumberFormat(u.ReferalUserCredits), users.Where(x => x.Id == thisUser.ReferedUserId.Value).FirstOrDefault().Name);
                }
                iCount += 1;
                retData.Add(new UserCreditLogGridViewModel()
                {
                    SNo                = iCount,
                    Id                 = u.Id,
                    UserName           = thisUser.Name,
                    Date               = u.CreatedAt.ToString("dd-MMM-yyyy hh:mm:ss tt"),
                    CreatedAt          = u.CreatedAt,
                    Credits            = LeadsHelpers.ToUsNumberFormat(u.Credits),
                    DisCountPercentage = u.DiscountPercentage.ToString(),
                    AmountPaid         = Math.Round(u.FinalAmount, 2).ToString(),
                    PackageName        = creditPackageService.GetAllCreditPackages().FirstOrDefault(x => x.Id == u.PackageId).PackageName,
                    ReferalInfo        = ReferalDetails
                });
            }
            retData = retData.OrderByDescending(x => x.CreatedAt).ToList();
            var jsonData = new { data = from emp in retData select emp };

            return(new JsonResult()
            {
                Data = jsonData,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                MaxJsonLength = Int32.MaxValue
            });
        }
        public ActionResult PerformUserScrub(FormCollection formCollection, string PhoneNos, string SelectedLeads)
        {
            bool isError = false;

            try
            {
                var        used          = userScrubService.GetScrubsByUserId(this.CurrentLoggedInUser.Id).Sum(x => x.ScrubCredits);
                Stopwatch  sw            = Stopwatch.StartNew();
                List <int> selectedLeads = JsonConvert.DeserializeObject <List <DropDownModel> >(SelectedLeads).Select(x => x.Id).ToList();
                if (string.IsNullOrEmpty(PhoneNos))
                {
                    HttpPostedFileBase file = Request.Files["ScrubFile"];
                    if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                    {
                        string ext         = Path.GetExtension(file.FileName);
                        string newFileName = Guid.NewGuid().ToString();
                        string path        = Path.Combine(Server.MapPath("~/Content/DataLoads/"), newFileName + ext);
                        file.SaveAs(path);

                        List <long>          UserScrubPhonesList = new List <long>();
                        DataTable            excelDt             = new DataTable();
                        string               phoneCol            = string.Empty;
                        List <DropDownModel> dt = new List <DropDownModel>();
                        if (ext.ToLower() == ".csv")
                        {
                            excelDt = ReadCsvFile(path, ref phoneCol);
                            dt      = FilterDatatableColoumn(excelDt.AsEnumerable(), excelDt, phoneCol);
                        }
                        else
                        {
                            excelDt = ReadExcelFile(ext, path, ref phoneCol);
                            dt      = FilterDatatableColoumn(excelDt.AsEnumerable(), excelDt, phoneCol);
                        }
                        foreach (var r in dt)
                        {
                            long number;
                            bool isSuccess = Int64.TryParse(r.Name, out number);
                            if (isSuccess)
                            {
                                UserScrubPhonesList.Add(number);
                            }
                        }
                        if (UserScrubPhonesList.Count > 0)
                        {
                            if ((this.CurrentLoggedInUser.CreditScore - used) >= UserScrubPhonesList.Count())
                            {
                                var matchedList    = leadService.ScrubPhoneNos(selectedLeads, UserScrubPhonesList).ToList();
                                var unmatchedCount = UserScrubPhonesList.Except(matchedList).ToList();
                                var dtList         = excelDt.AsEnumerable();
                                var matchedDt      = GetFilteredPhones(dtList, matchedList, phoneCol);
                                var unMatchedDt    = GetFilteredPhones(dtList, unmatchedCount, phoneCol);
                                sw.Stop();

                                //  Matched File Create
                                string matchedFileName = Guid.NewGuid().ToString();
                                CreatedDataTableCSV(matchedDt, matchedFileName);

                                // UnMatched File Create
                                string unMatchedFileName = Guid.NewGuid().ToString();
                                CreatedDataTableCSV(unMatchedDt, unMatchedFileName);

                                userScrubService.SaveUserScrub(UserScrubPhonesList.Count(), this.CurrentLoggedInUser.Id, SelectedLeads, matchedList.Count(), unmatchedCount.Count(), matchedFileName, unMatchedFileName, newFileName + ext, sw.Elapsed.Seconds);
                            }
                            else
                            {
                                ViewBag.NoCredits     = true;
                                ViewBag.IsFileError   = false;
                                ViewBag.CurrentUser   = this.CurrentLoggedInUser;
                                ViewBag.LeadTypesList = leadService.GetLeadTypes().Where(x => x.IsActive == true).ToList().Select(x => new DropDownModel()
                                {
                                    Name = x.Name,
                                    Id   = x.Id
                                }).OrderBy(x => x.Name).ToList();
                                var usedCredits1      = userScrubService.GetScrubsByUserId(this.CurrentLoggedInUser.Id).Sum(x => x.ScrubCredits);
                                var userTotalCredits1 = this.CurrentLoggedInUser.CreditScore;
                                ViewBag.remainingCredits = LeadsHelpers.ToUsNumberFormat(userTotalCredits1 - usedCredits1);
                                ViewBag.totalCredits     = LeadsHelpers.ToUsNumberFormat(userTotalCredits1);
                                return(View("Scrubber"));
                            }
                        }
                    }
                }
                else
                {
                    List <string> inputList           = PhoneNos.Split(',').ToList();
                    List <long>   UserScrubPhonesList = new List <long>();
                    foreach (var i in inputList)
                    {
                        long number;
                        bool isSuccess = Int64.TryParse(LeadsHelpers.ProcessNumber(i), out number);
                        if (isSuccess)
                        {
                            UserScrubPhonesList.Add(number);
                        }
                    }
                    if (UserScrubPhonesList.Count > 0)
                    {
                        if ((this.CurrentLoggedInUser.CreditScore - used) >= UserScrubPhonesList.Count())
                        {
                            var matchedList    = leadService.ScrubPhoneNos(selectedLeads, UserScrubPhonesList).ToList();
                            var unmatchedCount = UserScrubPhonesList.Except(matchedList).ToList();

                            sw.Stop();

                            //InputFile Create
                            string inputFileName = Guid.NewGuid().ToString();
                            CreateSaveCsvFile(inputFileName, UserScrubPhonesList);

                            //Matched File Create
                            string matchedFileName = Guid.NewGuid().ToString();
                            CreateSaveCsvFile(matchedFileName, matchedList);

                            // UnMatched File Create
                            string unMatchedFileName = Guid.NewGuid().ToString();
                            CreateSaveCsvFile(unMatchedFileName, unmatchedCount);

                            userScrubService.SaveUserScrub(UserScrubPhonesList.Count(), this.CurrentLoggedInUser.Id, SelectedLeads, matchedList.Count(), unmatchedCount.Count(), matchedFileName, unMatchedFileName, inputFileName + ".csv", sw.Elapsed.Seconds);
                        }
                        else
                        {
                            ViewBag.NoCredits     = true;
                            ViewBag.IsFileError   = false;
                            ViewBag.CurrentUser   = this.CurrentLoggedInUser;
                            ViewBag.LeadTypesList = leadService.GetLeadTypes().Where(x => x.IsActive == true).ToList().Select(x => new DropDownModel()
                            {
                                Name = x.Name,
                                Id   = x.Id
                            }).OrderBy(x => x.Name).ToList();
                            var usedCredits1      = userScrubService.GetScrubsByUserId(this.CurrentLoggedInUser.Id).Sum(x => x.ScrubCredits);
                            var userTotalCredits1 = this.CurrentLoggedInUser.CreditScore;
                            ViewBag.remainingCredits = LeadsHelpers.ToUsNumberFormat(userTotalCredits1 - usedCredits1);
                            ViewBag.totalCredits     = LeadsHelpers.ToUsNumberFormat(userTotalCredits1);
                            return(View("Scrubber"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isError = true;
            }
            ViewBag.NoCredits     = false;
            ViewBag.IsFileError   = isError;
            ViewBag.CurrentUser   = this.CurrentLoggedInUser;
            ViewBag.LeadTypesList = leadService.GetLeadTypes().Where(x => x.IsActive == true).ToList().Select(x => new DropDownModel()
            {
                Name = x.Name,
                Id   = x.Id
            }).OrderBy(x => x.Name).ToList();
            var usedCredits      = userScrubService.GetScrubsByUserId(this.CurrentLoggedInUser.Id).Sum(x => x.ScrubCredits);
            var userTotalCredits = this.CurrentLoggedInUser.CreditScore;

            ViewBag.remainingCredits = LeadsHelpers.ToUsNumberFormat(userTotalCredits - usedCredits);
            ViewBag.totalCredits     = LeadsHelpers.ToUsNumberFormat(userTotalCredits);
            return(View("Scrubber"));
        }