private string GetAuthorList() { AuthorService = new AuthorService(); List <object> AuthorObj = BaseService.GetObjectList(AuthorService, Request); AuthorCount = AuthorService.ObjectCount(); if (AuthorObj != null) { List <author> Authors = (List <author>)ObjectUtil.ConvertList(AuthorObj, typeof(List <author>)); List <author> AuthorsToSerialize = new List <author>(); if (Authors.Count > 0) { foreach (author Auhtor in Authors) { author NewClass = (author)ObjectUtil.GetObjectValues(new string[] { "id", "name", "address", "email", "phone" }, Auhtor); AuthorsToSerialize.Add(NewClass); } return(JsonConvert.SerializeObject(AuthorsToSerialize)); } return("0"); } return("0"); }
private string AddAuthor() { author author = (author)ObjectUtil.FillObjectWithMap(new author(), BaseService.ReqToDict(Request)); if (author != null) { AuthorService = new AuthorService(); author Std = null; if (StringUtil.NotNullAndNotBlank(author.id)) { Std = (author)AuthorService.Update(author); } else { Std = (author)AuthorService.Add(author); } if (Std == null) { return("0"); } author toSend = (author)ObjectUtil.GetObjectValues(new string[] { "id", "name", "address", "email", "phone" }, Std); return(JsonConvert.SerializeObject(toSend)); } return("0"); }
private string GetClassList() { ClassService = new ClassService(); List <object> ClassObj = BaseService.GetObjectList(ClassService, Request); ClassCoount = ClassService.ObjectCount(); if (ClassObj != null) { List <@class> Classes = (List <@class>)ObjectUtil.ConvertList(ClassObj, typeof(List <@class>)); List <@class> ClassesToSerialize = new List <@class>(); if (Classes.Count > 0) { foreach (@class CLass in Classes) { @class NewClass = (@class)ObjectUtil.GetObjectValues(new string[] { "id", "class_name" }, CLass); ClassesToSerialize.Add(NewClass); } return(JsonConvert.SerializeObject(ClassesToSerialize)); } return("0"); } return("0"); }
private string GetBookIssueList() { BookIssueService = new book_issueService(); List <object> book_issuesObj = BaseService.GetObjectList(BookIssueService, Request); BookIssueCount = BookIssueService.ObjectCount(); if (book_issuesObj != null) { List <book_issue> book_issues = (List <book_issue>)ObjectUtil.ConvertList(book_issuesObj, typeof(List <book_issue>)); List <book_issue> book_issuesToSerialize = new List <book_issue>(); if (book_issues.Count > 0) { foreach (book_issue BookIssue in book_issues) { book_issue book_issue = (book_issue)ObjectUtil.GetObjectValues(new string[] { "id", "book_record_id", "book_issue_id", "issue_id", "qty", "book_return" }, BookIssue); book_issuesToSerialize.Add(book_issue); } return(JsonConvert.SerializeObject(book_issuesToSerialize)); } return("0"); } return("0"); }
private string GetVisitsList() { VisitService = new VisitService(); List <object> VisitsObj = BaseService.GetObjectList(VisitService, Request); VisitCount = VisitService.ObjectCount(); if (VisitsObj != null) { List <visit> Visits = (List <visit>)ObjectUtil.ConvertList(VisitsObj, typeof(List <visit>)); List <visit> VisitsToSerialize = new List <visit>(); if (Visits.Count > 0) { foreach (visit Vst in Visits) { visit Visit = (visit)ObjectUtil.GetObjectValues(new string[] { "id", "student_id", "date", "info" }, Vst); VisitsToSerialize.Add(Visit); } return(JsonConvert.SerializeObject(VisitsToSerialize)); } return("0"); } return("0"); }
private string AddBook() { book Book = (book)ObjectUtil.FillObjectWithMap(new book(), BaseService.ReqToDict(Request)); if (Book != null) { bookService = new BookService(); book BookDB = null; if (Book.id != null && Book.id != "") { BookDB = (book)bookService.Update(Book); } else { BookDB = (book)bookService.Add(Book); } if (BookDB == null) { return("0"); } book toSend = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title", "publisher_id", "author_id", "category_id", "page", "review" }, BookDB); return(JsonConvert.SerializeObject(toSend)); } return("0"); }
private string GetCategoryList() { CategoryService = new CategoryService(); List <object> CategoryObj = BaseService.GetObjectList(CategoryService, Request); CategoryCount = CategoryService.ObjectCount(); if (CategoryObj != null) { List <category> Categories = (List <category>)ObjectUtil.ConvertList(CategoryObj, typeof(List <category>)); List <category> CategoriesToSerialize = new List <category>(); if (Categories.Count > 0) { foreach (category Category in Categories) { category NewClass = (category)ObjectUtil.GetObjectValues(new string[] { "id", "category_name" }, Category); CategoriesToSerialize.Add(NewClass); } return(JsonConvert.SerializeObject(CategoriesToSerialize)); } return("0"); } return("0"); }
private string AddCategory() { category category = (category)ObjectUtil.FillObjectWithMap(new category(), BaseService.ReqToDict(Request)); if (category != null) { CategoryService = new CategoryService(); category categoryDB = null; if (category.id != null && category.id != "") { categoryDB = (category)CategoryService.Update(category); } else { categoryDB = (category)CategoryService.Add(category); } if (categoryDB == null) { return("0"); } category toSend = (category)ObjectUtil.GetObjectValues(new string[] { "id", "category_name" }, categoryDB); return(JsonConvert.SerializeObject(toSend)); } return("0"); }
private string AddStudent() { student Student = (student)ObjectUtil.FillObjectWithMap(new student(), BaseService.ReqToDict(Request)); if (Student != null) { studentService = new StudentService(); student Std = null; if (StringUtil.NotNullAndNotBlank(Student.id)) { Std = (student)studentService.Update(Student); } else { Std = (student)studentService.Add(Student); } if (Std == null) { return("0"); } student toSend = (student)ObjectUtil.GetObjectValues(new string[] { "id", "name", "bod", "class_id", "address", "email" }, Std); return(JsonConvert.SerializeObject(toSend)); } return("0"); }
private string AddPublisher() { publisher publisher = (publisher)ObjectUtil.FillObjectWithMap(new publisher(), BaseService.ReqToDict(Request)); if (publisher != null) { PublisherService = new PublisherService(); publisher Std = null; if (StringUtil.NotNullAndNotBlank(publisher.id)) { Std = (publisher)PublisherService.Update(publisher); } else { Std = (publisher)PublisherService.Add(publisher); } if (Std == null) { return("0"); } publisher toSend = (publisher)ObjectUtil.GetObjectValues(new string[] { "id", "name", "address", "contact" }, Std); return(JsonConvert.SerializeObject(toSend)); } return("0"); }
private string AddClass() { @class Class = (@class)ObjectUtil.FillObjectWithMap(new @class(), BaseService.ReqToDict(Request)); if (Class != null) { ClassService = new ClassService(); @class classDB = null; if (Class.id != null && Class.id != "") { classDB = (@class)ClassService.Update(Class); } else { classDB = (@class)ClassService.Add(Class); } if (classDB == null) { return("0"); } @class toSend = (@class)ObjectUtil.GetObjectValues(new string[] { "id", "class_name" }, classDB); return(JsonConvert.SerializeObject(toSend)); } return("0"); }
private string GetPublisherList() { PublisherService = new PublisherService(); List <object> PublisherObj = BaseService.GetObjectList(PublisherService, Request); PublisherCount = PublisherService.ObjectCount(); if (PublisherObj != null) { List <publisher> Publishers = (List <publisher>)ObjectUtil.ConvertList(PublisherObj, typeof(List <publisher>)); List <publisher> PublishersToSerialize = new List <publisher>(); if (Publishers.Count > 0) { foreach (publisher Publisher in Publishers) { publisher NewClass = (publisher)ObjectUtil.GetObjectValues(new string[] { "id", "name", "address", "contact" }, Publisher); PublishersToSerialize.Add(NewClass); } return(JsonConvert.SerializeObject(PublishersToSerialize)); } return("0"); } return("0"); }
private string GetStudentList() { studentService = new StudentService(); List <object> StudentObj = BaseService.GetObjectList(studentService, Request); StudentCount = studentService.ObjectCount(); if (StudentObj != null) { List <student> Students = (List <student>)ObjectUtil.ConvertList(StudentObj, typeof(List <student>)); List <student> StudentsToSerialize = new List <student>(); if (Students.Count > 0) { foreach (student Std in Students) { @class StdClass = new @class() { id = Std.class_id, class_name = [email protected]_name }; student StdNew = (student)ObjectUtil.GetObjectValues(new string[] { "id", "name", "bod", "class_id", "address", "email" }, Std); StdNew.@class = StdClass; StudentsToSerialize.Add(StdNew); } return(JsonConvert.SerializeObject(StudentsToSerialize)); } return("0"); } return("0"); }
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 GetStudentById() { if (StringUtil.NotNullAndNotBlank(Request.Form["Id"])) { studentService = new StudentService(); student Std = studentService.GetByIdFull(Request.Form["Id"].ToString()); if (Std == null) { return("0"); } student toSend = (student)ObjectUtil.GetObjectValues(new string[] { "id", "name", "bod", "class_id", "address", "email" }, Std); return(JsonConvert.SerializeObject(toSend)); } return("0"); }
public override object Add(object Obj) { Refresh(); book book = (book)Obj; if (book.id == null) { book.id = StringUtil.GenerateRandomChar(7); } book CleanBook = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title", "page", "review", "category_id", "publisher_id", "isbn", "author_id" }, book); if (CleanBook.page == null) { CleanBook.page = 0; } book newbook = dbEntities.books.Add(CleanBook); try { dbEntities.SaveChanges(); return(newbook); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; // return null; } }
private string GetBookList() { bookService = new BookService(); List <object> BooksObj = BaseService.GetObjectList(bookService, Request); BookCount = bookService.ObjectCount(); if (BooksObj != null) { List <book> Books = (List <book>)ObjectUtil.ConvertList(BooksObj, typeof(List <book>)); List <book> BooksToSerialize = new List <book>(); if (Books.Count > 0) { foreach (book B in Books) { book Book = (book)ObjectUtil.GetObjectValues( new string[] { "id", "title", "page", "isbn", "img", "publisher_id", "author_id", "category_id", "review" }, B ); category newCat = (category)ObjectUtil.GetObjectValues(new string[] { "id", "category_name" }, B.category); B.publisher.books = null; B.author.books = null; B.category.books = null; ICollection <book_record> BRs = new List <book_record>(); foreach (book_record BR in B.book_record) { book_record BRNew = (book_record)ObjectUtil.GetObjectValues( new string[] { "id", "book_code", "available", "book_id" }, BR); BRs.Add(BRNew); } Book.category = newCat; Book.author = B.author; Book.publisher = B.publisher; Book.book_record = BRs; BooksToSerialize.Add(Book); } return(JsonConvert.SerializeObject(BooksToSerialize)); } return("0"); } return("0"); }
public override object Update(object Obj) { Refresh(); student StdObj = (student)Obj; student DBStudent = (student)GetById(StdObj.id); if (DBStudent == null) { return(null); } student CleanStudent = (student)ObjectUtil.GetObjectValues(new string[] { "id", "name", "bod", "address", "email", "class_id" }, StdObj); dbEntities.Entry(DBStudent).CurrentValues.SetValues(CleanStudent); dbEntities.SaveChanges(); return(StdObj); }
private string GetIssuesList() { issueService = new IssueService(); List <object> Issues = BaseService.GetObjectList(issueService, Request); IssueCount = issueService.ObjectCount(); if (Issues != null && Issues.Count > 0) { List <issue> IssuesToSerialize = new List <issue>(); foreach (issue Issue in Issues) { List <book_issue> BookIssues = new List <book_issue>(); foreach (book_issue BookIssue in Issue.book_issue) { book Book = (book)ObjectUtil.GetObjectValues( new string[] { "id", "title", "page", "isbn", "img", "publisher_id", "author_id", "category_id", "review" }, BookIssue.book_record.book ); book_record BRNew = (book_record)ObjectUtil.GetObjectValues( new string[] { "id", "book_code", "available", "book_id" }, BookIssue.book_record); book_issue BS = (book_issue)ObjectUtil.GetObjectValues(new string[] { "id", "book_record_id", "qty", "book_return", "book_issue_id", }, BookIssue); BRNew.book = Book; BS.book_record = BRNew; BookIssues.Add(BS); } issue IssueSerialize = (issue)ObjectUtil.GetObjectValues(new string[] { "id", "date", "type", "additional_info", "student_id" }, Issue); IssueSerialize.book_issue = BookIssues; IssuesToSerialize.Add(IssueSerialize); } return(JsonConvert.SerializeObject(IssuesToSerialize)); } else { return("0"); } }
public override object Update(object Obj) { Refresh(); book book = (book)Obj; book DBBook = (book)GetById(book.id); if (DBBook == null) { return(null); } book CleanBook = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title", "page", "review", "category_id", "publisher_id", "isbn", "author_id" }, book); if (CleanBook.page == null) { CleanBook.page = 0; } // dbEntities.Entry(book).CurrentValues. dbEntities.Entry(DBBook).CurrentValues.SetValues(CleanBook); dbEntities.SaveChanges(); return(book); }
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"); }
public async Task <ActionResult> PostSvc() { bool Access = UserValid(); WebResponse Response = new WebResponse(); if (/*!Access || */ !StringUtil.NotNullAndNotBlank(Request.Form["Action"])) { return(Json(Response)); } string Action = Request.Form["Action"].ToString(); PostService EntitySvc = new PostService(); Dictionary <string, object> PostProps = new Dictionary <string, object>() { { "id", null }, { "user_id", null }, { "title", null }, { "body", null }, { "date", null }, { "user", new Dictionary <string, object> { { "name", null } } }, { "type", null }, { "post_id", null } }; switch (Action) { case "List": string Scope = Request.Form["Scope"]; bool isPublic = (Scope != null && Scope.Equals("Public")) ; Response = MVCUtil.generateResponseList(EntitySvc, Request, LoggedUser, PostProps, typeof(post), isPublic); break; case "Form": if (!Access) { return(Json(Response)); } Response = MVCUtil.generateResponseWithForm(typeof(post), EntitySvc, Request); break; case "Post": if (!Access) { return(Json(Response)); } post post = (post)ObjectUtil.FillObjectWithMap(new post(), BaseService.ReqToDict(Request)); post.user_id = LoggedUser.id; if (post != null) { Response = MVCUtil.UpdateEntity(EntitySvc, post, new string[] { "id", "user_id", "title", "body", "date", "type", "post_id" }, Response); } break; case "Delete": if (!Access) { return(Json(Response)); } Response = MVCUtil.DeleteEntity(EntitySvc, Request, Response); break; case "Latest": // if (!Access) return Json(Response); string DateStr = Request.Form["timestamp"]; post CurrentPost = EntitySvc.findLatestPost(); if (CurrentPost != null) { DateTime Date = CurrentPost.created_date; DateStr = DateStr.Replace("T", " "); DateStr = DateStr.Replace("Z", ""); DateStr = DateStr.Replace("-", ""); try { Date = DateTime.ParseExact(DateStr, "yyyyMMdd HH:mm:ss.fff", CultureInfo.InvariantCulture); }catch (Exception ex) { Date = CurrentPost.created_date; } post LatestPost = new post(); DateTime requestTime = DateTime.Now; DateTime runningTime; Boolean update = true; bool hasUpdate = Date <= CurrentPost.created_date; while (CurrentPost.created_date <= Date) { runningTime = DateTime.Now; LatestPost = EntitySvc.findLatestPost(); if (LatestPost != null) { Date = LatestPost.created_date; } TimeSpan deltaTime = runningTime - requestTime; if (deltaTime.TotalMilliseconds >= 6000.0) { update = false; break; } } Response = new WebResponse(update ? 0 : 1, StringUtil.DateTimeToString(DateTime.Now), ObjectUtil.GetObjectValues(new string[] { "id", "title" }, LatestPost)); } else { Response = new WebResponse(0, "NoUpdate"); } break; default: break; } return(Json(Response)); }
protected void ButtonReturn_Click(object sender, EventArgs e) { try { book_issue BS = new book_issue(); BS.id = StringUtil.GenerateRandomChar(10); //BS.book_issue_id = (TextBoxIssueRecordId.Text.Trim()); //add student Student = (student)StudentService.GetById(TextBoxStudentID.Text); if (Student == null) { return; } string Student_ID = Student.id; string RecId = (TextBoxIssueRecordId.Text.Trim()); List <object> BookIssuesOBJ = BookIssueService.SearchAdvanced(new Dictionary <string, object>() { { "student_id", Student_ID }, { "book_record_id", RecId }, { "issue_type", "issue" }, { "book_return", "0" } }); if (BookIssuesOBJ == null || BookIssuesOBJ.Count == 0) { return; } book_issue reffBookIssue = (book_issue)BookIssuesOBJ.ElementAt(0); if (reffBookIssue.book_return != 0) { return; } BS.book_issue_id = reffBookIssue.id; // book_issue reffBookIssue = (book_issue)BookIssueService.GetById(BS.book_issue_id); if (!BookIssue.ExistBookRecord(BS.book_issue_id, BookIssuesReturn) && null != reffBookIssue) { //Check book_isue where book_rec_id = rec book_return != null || 0 and issue.student_id = std_id string StudentId = TextBoxStudentID.Text; if (BookIssueService.GetByBookIssueIdReturned(reffBookIssue.id).Count == 0) { book_record BookRecord = (book_record)bookRecordService.GetById(reffBookIssue.book_record_id); //BS.book_issue2 = reffBookIssue; BS.book_record_id = BookRecord.id; book Book = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title" }, BookRecord.book); book_record BookRec = (book_record)ObjectUtil.GetObjectValues(new string[] { "id", "book_id", "available" }, BookRecord); BookRec.book = Book; BS.book_record = BookRec; BookIssuesReturn.Add(BS); } } }catch (HttpUnhandledException ex) { throw ex; } ButtonSearch_Click(sender, e); ViewState["BookIssuesReturn"] = BookIssuesReturn; PopulateBooksToReturn(); }