private string GetBookStudentIssue() { if (StringUtil.NotNullAndNotBlank(Request.Form["rec_id"]) && StringUtil.NotNullAndNotBlank(Request.Form["student_id"])) { BookIssueService = new book_issueService(); bookRecordService = new Book_recordService(); studentService = new StudentService(); student Std = studentService.GetByIdFull(Request.Form["student_id"].ToString()); if (Std == null) { return("0"); } List <object> BookIssuesOBJ = BookIssueService.SearchAdvanced(new Dictionary <string, object>() { { "student_id", Request.Form["student_id"].ToString() }, { "book_record_id", Request.Form["rec_id"].ToString() }, { "book_return", "0" }, { "issue_type", "issue" }, }); if (BookIssuesOBJ == null || BookIssuesOBJ.Count == 0) { return("0"); } book_issue StudentBookIssue = (book_issue)BookIssuesOBJ.ElementAt(0); if (StudentBookIssue == null) { return("0"); } book_record BookRecord = (book_record)bookRecordService.GetById(Request.Form["rec_id"]); if (BookRecord == null) { return("0"); } book_record BookRecordToSend = (book_record)ObjectUtil.GetObjectValues(new string[] { "id", "book_id", "available" }, BookRecord); if (BookRecord.book != null) { BookRecordToSend.book = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title" }, BookRecord.book); } book_issue BookIssueToSend = (book_issue)ObjectUtil.GetObjectValues(new string[] { "id", "book_record_id", "book_return" }, StudentBookIssue); BookIssueToSend.book_record = BookRecordToSend; return(JsonConvert.SerializeObject(BookIssueToSend)); } return("0"); }
private string GetBookRecordById() { if (StringUtil.NotNullAndNotBlank(Request.Form["Id"])) { bookRecordService = new Book_recordService(); book_record BookRecord = (book_record)bookRecordService.GetById(Request.Form["Id"]); if (BookRecord == null) { return("0"); } book_record toSend = (book_record)ObjectUtil.GetObjectValues(new string[] { "id", "book_id", "available" }, BookRecord); if (BookRecord.book != null) { toSend.book = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title" }, BookRecord.book); } return(JsonConvert.SerializeObject(toSend)); } return("0"); }
private issue IssueBook() { if (StringUtil.NotNullAndNotBlank(Request.Form["student_id"]) && StringUtil.NotNullAndNotBlank(Request.Form["book_recs"])) { issueService = new IssueService(); studentService = new StudentService(); bookRecordService = new Book_recordService(); BookIssueService = new book_issueService(); string StudentId = Request.Form["student_id"]; student Student = (student)studentService.GetById(StudentId); if (Student == null) { return(null); } string IssueID = StringUtil.GenerateRandomNumber(9); issue Issue = new issue(); Issue.user_id = User.id; Issue.id = IssueID; Issue.type = "issue"; Issue.date = DateTime.Now; Issue.student_id = Student.id; Issue.addtional_info = "test"; string[] BookRecIds = Request.Form["book_recs"].Split(';'); if (BookRecIds.Length < 1) { return(null); } if (null == issueService.Add(Issue)) { return(null); } List <book_issue> BookIssues = new List <book_issue>(); foreach (string Id in BookRecIds) { book_record BR = (book_record)bookRecordService.GetById(Id); if (BR == null || BR.available == 0) { continue; } book_issue BookIssue = new book_issue(); BookIssue.id = StringUtil.GenerateRandomChar(10); BookIssue.issue_id = IssueID; BookIssue.book_record_id = Id; BookIssue.qty = 1; BookIssues.Add(BookIssue); BookIssueService.Add(BookIssue); BR.available = 0; bookRecordService.Update(BR); } Issue.book_issue = BookIssues; return(Issue); } return(null); }