Exemplo n.º 1
0
        public ActionResult SubmitHotMarkRequest(string CardNo)
        {
            long ID = 0;

            if (IsDuplicateEntry(CardNo, "", "H", null, out ID))
            {
                return(Json(new { IsSuccess = ID, ErrorMessage = CustomMessages.RequestAlreadyExists }, JsonRequestBehavior.AllowGet));
            }

            bool flag = false;
            CustomerCardDataAccess obj = new CustomerCardDataAccess();
            var AlreadyHot             = obj.IsCardHotMarked(CardNo);

            if (AlreadyHot == "Success")
            {
                flag = CardHotMarkMethods.GenerateHotMarkRequest(CardNo);



                return(Json(new { IsSuccess = true, ErrorMessage = CustomMessages.Success }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { IsSuccess = false, ErrorMessage = AlreadyHot }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        public ActionResult AutomaticHotMark(HttpPostedFileBase postedFile)
        {
            long ID = 0;
            CustomerCardDataAccess result = new CustomerCardDataAccess();
            //flag = result.CardHotMark(CardNo);

            string filePath = string.Empty;

            try
            {
                //if (postedFile != null)
                //{
                var    filePathData = new FilePathDataAccess().GetFilePathByTypeID(((int)Constants.enPathType.Import).ToString());
                string path         = filePathData?.Path ?? @"C:\Users\Mohsin\Desktop\ImportedFile\";
                string filename     = "Hotmark.csv";
                //string path = Server.MapPath("~/CardHotMark/");
                int found = 0, notFound = 0, alreadyhot = 0, requestexist = 0;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                filePath = path + Path.GetFileName(filename);
                string extension = Path.GetExtension(filename);
                if (extension == ".csv" || extension == ".CSV")
                {
                    //postedFile.SaveAs(filePath);
                    string csvData = System.IO.File.ReadAllText(filePath).Replace("\r\n", "$$&$$");
                    //var data = csvData.Split('\n', '\r');
                    var data               = csvData.Split(new[] { "$$&$$" }, StringSplitOptions.None).Where(e => !string.IsNullOrWhiteSpace(e)).Select(e => e.Trim()).ToArray();
                    var AllowedQuantity    = ConfigurationManager.AppSettings["HotFile"];
                    int AllowedQuantityInt = Convert.ToInt32(AllowedQuantity);
                    if (Convert.ToInt32(data.Count()) - 1 > AllowedQuantityInt)
                    {
                        return(Json("Please Upload maximum of " + AllowedQuantityInt + " records", JsonRequestBehavior.AllowGet));
                    }
                    foreach (string row in data.Skip(1).ToList())
                    {
                        //foreach (var item in row.Split(','))
                        //{
                        if (string.IsNullOrWhiteSpace(row))
                        {
                            continue;
                        }

                        var datarow = row.Split(',');
                        if (datarow.Length >= 2)
                        {
                            var cardno = datarow[0];
                            var expiry = new DateTime(int.Parse(datarow[1].Substring(0, 4)), int.Parse(datarow[1].Substring(4, 2)), int.Parse(datarow[1].Substring(6, 2)), 0, 0, 0);
                            if (!string.IsNullOrEmpty(cardno))
                            {
                                if (IsDuplicateEntry(cardno, "", "H", null, out ID))
                                {
                                    //notFound++;
                                    requestexist++;
                                    continue;
                                }

                                var AlreadyHot = new CustomerCardDataAccess().IsCardHotMarked(cardno);
                                if (AlreadyHot == "Success")
                                {
                                    var isSuccess = CardHotMarkMethods.GenerateHotMarkRequest(cardno, expiry);
                                    //var isSuccess = result.CardHotMark(cardno, expiry);
                                    if (!isSuccess)
                                    {
                                        notFound++;
                                    }
                                    else
                                    {
                                        found++;
                                    }
                                }
                                else
                                {
                                    //notFound++;
                                    alreadyhot++;
                                }
                            }
                        }
                        else
                        {
                            return(Json("Please Select Valid .csv file", JsonRequestBehavior.AllowGet));
                        }

                        //}
                    }
                    //TempData["mesage"] = "Sucessfully Retreived";
                    return(Json($"Succesfull: {found}, Card Data Not Found: {notFound},Card Already Hot: {alreadyhot},Request Already Exists: {requestexist}", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //TempData["mesage"] = "Please Select Valid .csv file";
                    return(Json("Please Select Valid .csv file", JsonRequestBehavior.AllowGet));
                }
                //}
            }
            catch (Exception ex)
            {
                //TempData["mesage"] = "Path or File Not Found";
                return(Json("Path or File Not Found", JsonRequestBehavior.AllowGet));
                //throw ex;
            }
            // return View("CardHotMarkScreen");
        }