region Booking public void CheckOutBook int id try var bookExtraData m

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#region Booking
public void CheckOutBook(int id) {
try {
var bookExtraData = mapper.Map<BookExtraData, BookExtraDataDTO>(
unitOfWork.BookExtraData.GetSingle(x =>
x.Book.Id == id)
);
if (bookExtraData == null)
throw new EntityNotFoundException();
bookExtraData.InStock--;
unitOfWork.BookExtraData.Update(
mapper.Map<BookExtraDataDTO, BookExtraData>(bookExtraData)
);
unitOfWork.Commit();
} catch (EntityNotFoundException e) {
throw new BookNotFoundException(e.Message, e);
} catch (AmountOutOfRangeException e) {
throw new AmountOutOfRangeException(e.Message, e);
}
}
public void ReturnBook(int id) {
try {
var bookExtraData = mapper.Map<BookExtraData, BookExtraDataDTO>(
unitOfWork.BookExtraData.GetSingle(x =>
x.Id == id)
);
if (bookExtraData == null)
throw new EntityNotFoundException();
bookExtraData.InStock++;
unitOfWork.BookExtraData.Update(
mapper.Map<BookExtraDataDTO, BookExtraData>(bookExtraData)
);
unitOfWork.Commit();
} catch (EntityNotFoundException e) {
throw new BookNotFoundException(e.Message, e);
} catch (AmountOutOfRangeException e) {
throw new AmountOutOfRangeException(e.Message, e);
}
}
#endregion