public void UpdateISBNBag(ISBNBag ISBNBag) { _ISBNBagRepository.Update(ISBNBag); }
public IHttpActionResult UploadISBN(ISBNBagModel _UploadISBN) { try { DataTable InvalidIsbn = new DataTable(); InvalidIsbn.Columns.Add("Invalid Isbn"); InvalidIsbn.Columns.Add("Reason"); IList <ApplicationSetUp> _ApplicationSetUpList = _ApplicationSetUp.Table.Where(x => x.key == "ExcelFilePath" && x.Deactivate == "N").ToList(); var ExcelPath = _ApplicationSetUpList.Select(Au => new { ExcelUploadPath = Au.keyValue, }); string status = ""; string URL = ExcelPath.FirstOrDefault().ExcelUploadPath; int mint_SheetNameFlag = 0; DataTable mdt_ISBNBag = new DataTable(); DataTable mdt_Stock = new DataTable(); DataTable mdt_AccessCode = new DataTable(); mdt_Stock = CreateDataTableFromExcelDAL(URL, _UploadISBN.FileName, mint_SheetNameFlag); if (mdt_Stock == null) { status = "Excel sheet(Sheet1) does not contain isbn's no."; return(Json(new { status, InvalidIsbn })); } if (((mdt_Stock != null) && mdt_Stock.Rows.Count < 1)) { status = "Excel sheet(Sheet1) does not contain isbn's no."; return(Json(new { status, InvalidIsbn })); } if (((mdt_Stock != null))) { mdt_Stock.TableName = "ISBNBag"; if ((mdt_Stock.Columns.Count > 1)) { if (((mdt_Stock.Columns[0].ColumnName.ToLower() != "isbn"))) { // lit_retval.Text = "Incorrect excel sheet format. Please download correct file format." status = "Invalid excel sheet format. Please download correct file format."; return(Json(new { status, InvalidIsbn })); } } var duplicates = mdt_Stock.AsEnumerable().GroupBy(r => r[0]).Where(gr => gr.Count() > 1); foreach (var Row in duplicates) { var row = InvalidIsbn.NewRow(); row["Invalid Isbn"] = Row.Key; row["Reason"] = "Duplicate isbn found in excel"; InvalidIsbn.Rows.Add(row); } DataTable real_datatable = new DataTable(); real_datatable = RemoveDuplicatesRecords(mdt_Stock); Regex regex = new Regex(@"^\d$"); int flag = 0; IList <ISBNBag> _IListIsbn = new List <ISBNBag>(); foreach (DataRow Row in real_datatable.Rows) { ISBNBag _ISBNBag = new ISBNBag(); try { if (Row[0].ToString() != "" && System.Text.RegularExpressions.Regex.IsMatch(Decimal.Parse(Row[0].ToString(), System.Globalization.NumberStyles.Any).ToString(), "^[0-9]*$") && Decimal.Parse(Row[0].ToString(), System.Globalization.NumberStyles.Any).ToString().Trim().Length == 13) { _ISBNBag.ISBN = Decimal.Parse(Row[0].ToString(), System.Globalization.NumberStyles.Any).ToString(); _ISBNBag.ProductTypeid = _UploadISBN.ProductType; _ISBNBag.Used = "N"; _ISBNBag.Deactivate = "N"; _ISBNBag.EnteredBy = _UploadISBN.EnteredBy; _ISBNBag.EntryDate = DateTime.Now; _ISBNBag.ProductId = null; int id = _IISBNService.GetIsbnByIsbn(_ISBNBag.ISBN); if (id == 0) { _IListIsbn.Add(_ISBNBag); flag = 1; } else { var row = InvalidIsbn.NewRow(); row["Invalid Isbn"] = Decimal.Parse(Row[0].ToString(), System.Globalization.NumberStyles.Any).ToString(); row["Reason"] = "Isbn already exists in database"; InvalidIsbn.Rows.Add(row); } } else { flag = 2; var row = InvalidIsbn.NewRow(); row["Invalid Isbn"] = Decimal.Parse(Row[0].ToString(), System.Globalization.NumberStyles.Any).ToString(); row["Reason"] = "Invalid Isbn"; InvalidIsbn.Rows.Add(row); } } catch (Exception ex) { var row = InvalidIsbn.NewRow(); row["Invalid Isbn"] = Row[0].ToString(); row["Reason"] = ex.Message; status = ex.Message; InvalidIsbn.Rows.Add(row); } } if (_IListIsbn.Count > 0) { _IISBNService.InsertISBNBag(_IListIsbn); status = "OK"; //return Json(status); } if (InvalidIsbn.Rows.Count > 0) { if (flag == 1) { status = status + ",NOK"; } else if (flag == 2) { status = "No isbn have uploaded. All isbn are duplicates."; } } } return(Json(new { status, InvalidIsbn })); } catch (ACSException ex) { _ILog.LogException("", Severity.ProcessingError, "ISBNMasterController.cs", "UploadISBN", ex); return(Json(new { ex.InnerException.Message })); } catch (Exception ex) { _ILog.LogException("", Severity.ProcessingError, "ISBNMasterController.cs", "UploadISBN", ex); return(Json(new { ex.InnerException.Message })); } }
public ISBNBag GetISBNBagById(ISBNBag ISBNBag) { return(_ISBNBagRepository.Table.Where(x => x.Id == ISBNBag.Id && x.Deactivate == "N" && x.Used == "N").FirstOrDefault()); }