public JsonResult BatchNoGet() { int BatchNo = 100; objContext = new OutwardContext(); try { BatchNo = objContext.BatchNoGet(); } catch (Exception ex) { return(Json("Failure")); } return(Json(BatchNo, JsonRequestBehavior.AllowGet)); }
public ActionResult UploadImage(List <HttpPostedFileBase> file, UploadImageModel obj) { HttpPostedFileBase MICRFile = null; string strMICRPath = ""; UploadImageModel objImage; try { //Get Session information of Loggedin user UserInfo objUser = new UserInfo();// UserInfoGet(); //Find text file for MICR information if (file.Count > 0) { MICRFile = file.Where(x => x.ContentType.ToLower() == "text/plain").FirstOrDefault(); if (MICRFile != null && MICRFile.ContentLength > 0) { strMICRPath = MICRSave(MICRFile); } } if (strMICRPath != "") { List <string> listCheque = System.IO.File.ReadLines(strMICRPath) .Select(r => r.TrimEnd('\n')).ToList(); string line; StreamReader file2 = new StreamReader(Server.MapPath("~/FileConfiguration/ImageUploadConfiguration.txt")); while ((line = file2.ReadLine()) != null) { columns = line.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } file2.Close(); if (columns != null) { AssignIndex(); } else { throw new Exception("Cheque configuration is Missing. Please Contact your Administrator!!!"); } List <UploadImageModel> ImageList = new List <UploadImageModel>(); List <UploadImageModel> FailedChequeList = new List <UploadImageModel>(); foreach (string chequeLine in listCheque) { if (!string.IsNullOrEmpty(chequeLine)) { string[] strColumn = columns.Where(x => x.Contains("ChequeNo")).FirstOrDefault().Split('_'); objImage = new UploadImageModel(); objImage.ChequeNo = chequeLine.Substring(ChqNoStart, ChqNoEnd); objImage.SortCode = chequeLine.Substring(SortCodeStart, SortCodeEnd); objImage.SerialNo = chequeLine.Substring(SerialNoStart, SerialNoEnd); objImage.TransCode = chequeLine.Substring(TransStart, TransEnd); objImage.imgFront = chequeLine.Substring(ImageFStart, ImageFEnd); objImage.imgBack = chequeLine.Substring(ImageBStart, ImageBEnd); objImage.imgGray = chequeLine.Substring(ImageGStart, ImageGEnd); //When there is any mismatch of a Cheque with image if (string.IsNullOrEmpty(objImage.imgFront) || string.IsNullOrEmpty(objImage.imgBack) || string.IsNullOrEmpty(objImage.imgGray)) { FailedChequeList.Add(objImage); continue; } //Get Binary Data of files objImage.imgFrontByte = FileBinaryGet(file.Where(x => x.FileName.ToLower() == objImage.imgFront.ToLower()).FirstOrDefault()); objImage.imgBackByte = FileBinaryGet(file.Where(x => x.FileName.ToLower() == objImage.imgBack.ToLower()).FirstOrDefault()); objImage.imgGrayByte = FileBinaryGet(file.Where(x => x.FileName.ToLower() == objImage.imgGray.ToLower()).FirstOrDefault()); //When there is any mismatch of a Cheque with image if (objImage.imgFrontByte == null || objImage.imgBackByte == null || objImage.imgGrayByte == null) { FailedChequeList.Add(objImage); continue; } objImage.Amount = Convert.ToInt64(chequeLine.Substring(AmtStart, AmtEnd)); objImage.AccountNo = chequeLine.Substring(AccStart, AccEnd); objImage.PresentmentDate = chequeLine.Substring(DateStart, DateEnd); objImage.BranchCode = chequeLine.Substring(BranchCodeStart, BranchCodeEnd); objImage.Narration = chequeLine.Substring(NarationStart, NarationEnd); objImage.BatchNo = obj.BatchNo; //Sending to DBContext objContext = new OutwardContext(); objContext.ChequeSave(objImage, objUser); //Adding it to List //ImageList.Add(objImage); } } // foreach end ViewBag.FailedCheque = FailedChequeList; //ViewBag.FileStatus = "File uploaded successfully."; } } catch (Exception ex) { ViewBag.Result = ex.Message; return(View("OutwardPage")); //return Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet); } ViewBag.Result = "Success"; return(View("OutwardPage")); //return Json("Success", JsonRequestBehavior.AllowGet); }