public static LibraryRecordDetailDTO MapTo(LibraryRecord record) { var books = new List <BookRecordDTO>(); foreach (var book in record.Books) { books.Add(new BookRecordDTO() { id = book.BookId.Value, amount = book.BookAmount.Amount.ToString(), title = book.Title.Value }); } return(new LibraryRecordDetailDTO() { Id = record.Id.Value, Books = books, CreatedDate = record.CreatedDate, IsExpired = DateTime.UtcNow > record.ReturnDate, ReturnFine = record.ReturnFine.Value, ReturnDate = record.ReturnDate, Username = record.User.Name + " " + record.User.Surname }); }
public void AddNewBook([FromBody] string bookName) { LibraryRecord newRecord = new LibraryRecord(); newRecord.BookName = bookName; _ctx.LibraryRecords.Add(newRecord); _ctx.SaveChanges(); }
public void Insert(LibraryRecord libraryRecord) { try { dbcontext.LibraryRecordContext.Add(libraryRecord); dbcontext.SaveChanges(); } catch { throw; } }
public bool LoadModelIntoPrinter(LibraryRecord record, ModelLoadingManager.LoadFailedCallback onFailCallback) { Form1.debugLogger.Add("LoadModelIntoPrinter()", "loading model into printer.", DebugLogger.LogType.Secondary); var num = LoadModelIntoPrinter(record.cachefilename, onFailCallback) ? 1 : 0; if (num == 0) { return(num != 0); } Form1.debugLogger.Add("LoadModelIntoPrinter()", "Model loaded into printer.", DebugLogger.LogType.Secondary); Form1.debugLogger.Add("LoadModelIntoPrinter()", "OpenGL GetError(): " + GL.GetError().ToString() + ".", DebugLogger.LogType.Secondary); return(num != 0); }
//删除 public bool Delete(int ID) { try { LibraryRecord LibraryRecord = new LibraryRecord { LibraryRecordID = ID }; dbcontext.LibraryRecordContext.Attach(LibraryRecord); dbcontext.LibraryRecordContext.Remove(LibraryRecord); //dbcontext.SaveChanges(); return(true); } catch (System.Data.SqlClient.SqlException e) { throw e; } }
//更新IsPass状态 public void UpdateIsPass(int ID, bool isPass) { try { LibraryRecord NewLibraryRecord = dbcontext.LibraryRecordContext.Find(ID); if (NewLibraryRecord == null) { return; } NewLibraryRecord.IsPass = isPass; dbcontext.SaveChanges(); } catch { throw; } }
public async Task Create(LibraryRecordCreateDTO libraryRecordDto) { var user = await userRepository.GetByIdAsync(new UserId(libraryRecordDto.userId)); List <BookRecord> books = new List <BookRecord>(); foreach (var book in libraryRecordDto.books) { var amount = Convert.ToInt32(book.amount); var bookId = new BookId(book.id); await CheckBookAvailibility(bookId, book.title, amount); books.Add(new BookRecord(bookId, new BookAmount(amount), new BookTitle(book.title))); } var libraryRecord = LibraryRecord.Create(UserMapper.MapTo(user), books); await libraryRecordRepository.InsertNewAsync(libraryRecord); }
//更新借阅记录 public bool Update(LibraryRecord libraryRecord) { try { LibraryRecord NewLibraryRecord = dbcontext.LibraryRecordContext.Find(libraryRecord.LibraryRecordID); NewLibraryRecord.BorrowTime = libraryRecord.BorrowTime; NewLibraryRecord.ContractID = libraryRecord.ContractID; NewLibraryRecord.EntryPerson = libraryRecord.EntryPerson; NewLibraryRecord.IsPass = libraryRecord.IsPass; NewLibraryRecord.ReturnTime = libraryRecord.ReturnTime; NewLibraryRecord.SecrecyLevel = libraryRecord.SecrecyLevel; NewLibraryRecord.Sort = libraryRecord.Sort; NewLibraryRecord.UserInfoID = libraryRecord.UserInfoID; dbcontext.SaveChanges(); return(true); } catch { return(false); } }