-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sailesh Rijal
committed
May 21, 2023
1 parent
2a2c609
commit 962427c
Showing
224 changed files
with
98,415 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryManagementSystem", "LibraryManagementSystem\LibraryManagementSystem.csproj", "{EC21F8DD-8A48-47C0-A10C-F4E40BE30814}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EC21F8DD-8A48-47C0-A10C-F4E40BE30814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EC21F8DD-8A48-47C0-A10C-F4E40BE30814}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EC21F8DD-8A48-47C0-A10C-F4E40BE30814}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EC21F8DD-8A48-47C0-A10C-F4E40BE30814}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace LibraryManagementSystem.Constants | ||
{ | ||
public static class AppConstants | ||
{ | ||
public const string Name = "eLibrary"; | ||
public const string Version = "1.0.0"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace LibraryManagementSystem.Constants | ||
{ | ||
public static class Grades | ||
{ | ||
public static List<string> Value = new(){ | ||
"Grade 1", | ||
"Grade 2", | ||
"Grade 3", | ||
"Grade 4", | ||
"Grade 5", | ||
"Grade 6", | ||
"Grade 7", | ||
"Grade 8", | ||
"Grade 9", | ||
"Grade 10" | ||
}; | ||
|
||
public static SelectList GetSelectLists(string selectedValue) => new SelectList(Value, selectedValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace LibraryManagementSystem.Constants | ||
{ | ||
public static class UserRoles | ||
{ | ||
public const string Admin = "Admin"; | ||
public const string User = "User"; | ||
|
||
public static readonly List<string> Value = new List<string>() | ||
{ | ||
Admin, | ||
User | ||
}; | ||
|
||
public static SelectList GetSelectLists(string selectedValue) | ||
{ | ||
return new SelectList(Value, selectedValue); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using AspNetCoreHero.ToastNotification.Abstractions; | ||
using LibraryManagementSystem.Models; | ||
using LibraryManagementSystem.ViewModels; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace LibraryManagementSystem.Controllers | ||
{ | ||
public class AccountController : Controller | ||
{ | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
private readonly SignInManager<ApplicationUser> _signInManager; | ||
private readonly INotyfService _notyfService; | ||
|
||
public AccountController(UserManager<ApplicationUser> userManager, | ||
SignInManager<ApplicationUser> signInManager, | ||
INotyfService notyfService) | ||
{ | ||
_userManager = userManager; | ||
_signInManager = signInManager; | ||
_notyfService = notyfService; | ||
} | ||
|
||
[HttpGet] | ||
[AllowAnonymous] | ||
public IActionResult Login() | ||
{ | ||
if (_signInManager.IsSignedIn(User)) return RedirectToAction("Index", "Home"); | ||
return View(new LoginVm()); | ||
} | ||
|
||
[HttpPost] | ||
[AllowAnonymous] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Login(LoginVm loginVM) | ||
{ | ||
try | ||
{ | ||
if (!ModelState.IsValid) { return View(loginVM); } | ||
|
||
var user = await _userManager.FindByNameAsync(loginVM.UserName!); | ||
|
||
if (user == null) | ||
{ | ||
throw new Exception("User not found"); | ||
} | ||
|
||
var checkPassword = await _userManager.CheckPasswordAsync(user, loginVM.Password!); | ||
|
||
if (!checkPassword) | ||
{ | ||
throw new Exception("Password is incorrect"); | ||
} | ||
|
||
if(!user.Status) | ||
{ | ||
throw new Exception("User is not active. Please contact admin"); | ||
} | ||
|
||
var result = await _signInManager.PasswordSignInAsync(user, loginVM.Password!, loginVM.IsRemember, false); | ||
|
||
if (!result.Succeeded) | ||
{ | ||
throw new Exception("Login failed"); | ||
} | ||
_notyfService.Success("Login successfully"); | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_notyfService.Error(ex.Message); | ||
return View(loginVM); | ||
} | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Logout() | ||
{ | ||
await _signInManager.SignOutAsync(); | ||
_notyfService.Success("Logout successfully"); | ||
return RedirectToAction("Login"); | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult AccessDenied() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
using AspNetCoreHero.ToastNotification.Abstractions; | ||
using LibraryManagementSystem.Dtos.BookDto; | ||
using LibraryManagementSystem.Models; | ||
using LibraryManagementSystem.Repositories.Interface; | ||
using LibraryManagementSystem.Services.Interface; | ||
using LibraryManagementSystem.ViewModels.BookViewModel; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace LibraryManagementSystem.Controllers | ||
{ | ||
public class BookController : Controller | ||
{ | ||
private readonly IBookService _bookService; | ||
private readonly IBookRepository _bookRepository; | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
private readonly INotyfService _notyfService; | ||
private readonly ICategoryRepository _categoryRepository; | ||
|
||
public BookController(IBookService bookService, IBookRepository bookRepository, UserManager<ApplicationUser> userManager, INotyfService notyfService, ICategoryRepository categoryRepository) | ||
{ | ||
_bookService = bookService; | ||
_bookRepository = bookRepository; | ||
_userManager = userManager; | ||
_notyfService = notyfService; | ||
_categoryRepository = categoryRepository; | ||
} | ||
|
||
public async Task<IActionResult> Index() | ||
{ | ||
var books = await _bookRepository.GetAllBooksWithUserAndCategory(); | ||
var vm = books.Select(x => new BookVm() | ||
{ | ||
Id = x.Id, | ||
Name = x.Name, | ||
Author = x.Author, | ||
NumberOfCopies = x.NumberOfCopies, | ||
AvailableCopies = x.AvailableCopies, | ||
CategoryName = x.Category!.Name, | ||
}).ToList(); | ||
return View(vm); | ||
} | ||
|
||
public async Task<IActionResult> Create() | ||
{ | ||
var categories = await _categoryRepository.GetAllAsync(); | ||
var vm = new CreateBookVm() | ||
{ | ||
Categories = categories.Select(x => new SelectListItem() | ||
{ | ||
Text = x.Name, | ||
Value = x.Id.ToString() | ||
}).ToList() | ||
}; | ||
return View(vm); | ||
} | ||
|
||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Create(CreateBookVm vm) | ||
{ | ||
if (!ModelState.IsValid) return View(vm); | ||
try | ||
{ | ||
var dto = new CreateBookDto() | ||
{ | ||
Name = vm.Name, | ||
Author = vm.Author, | ||
Publication = vm.Publication, | ||
NumberOfCopies = vm.NumberOfCopies, | ||
CategoryId = vm.CategoryId, | ||
CreatedUserId = _userManager.GetUserId(User) | ||
}; | ||
await _bookService.CreateAsync(dto); | ||
_notyfService.Success("Book created successfully"); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_notyfService.Error(ex.Message); | ||
return View(vm); | ||
} | ||
} | ||
|
||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Delete(int id) | ||
{ | ||
try | ||
{ | ||
await _bookService.DeleteAsync(id); | ||
_notyfService.Success("Book deleted successfully"); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_notyfService.Error(ex.Message); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
} | ||
|
||
|
||
[HttpGet] | ||
public async Task<IActionResult> Edit(int id) | ||
{ | ||
try | ||
{ | ||
var book = await _bookRepository.GetByAsync(x => x.Id == id); | ||
var categories = await _categoryRepository.GetAllAsync(); | ||
var vm = new EditBookVm() | ||
{ | ||
Id = book.Id, | ||
Name = book.Name, | ||
Author = book.Author, | ||
Publication = book.Publication, | ||
NumberOfCopies = book.NumberOfCopies, | ||
AvailableCopies = book.AvailableCopies, | ||
CategoryId = book.CategoryId, | ||
Categories = categories.Select(x => new SelectListItem() | ||
{ | ||
Text = x.Name, | ||
Value = x.Id.ToString() | ||
}).ToList() | ||
}; | ||
return View(vm); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_notyfService.Error(ex.Message); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
} | ||
|
||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Edit(EditBookVm vm) | ||
{ | ||
if (!ModelState.IsValid) return View(vm); | ||
var currentUser = await _userManager.GetUserAsync(User); | ||
try | ||
{ | ||
if(vm.AvailableCopies > vm.NumberOfCopies) | ||
{ | ||
_notyfService.Error("Available copies can't be greater than number of copies"); | ||
return View(vm); | ||
} | ||
var dto = new UpdateBookDto() | ||
{ | ||
Id = vm.Id, | ||
Name = vm.Name, | ||
Author = vm.Author, | ||
Publication = vm.Publication, | ||
NumberOfCopies = vm.NumberOfCopies, | ||
AvailableCopies = vm.AvailableCopies, | ||
CategoryId = vm.CategoryId, | ||
ModifiedUserId = _userManager.GetUserId(User) | ||
}; | ||
await _bookService.UpdateAsync(dto); | ||
_notyfService.Success("Book updated successfully"); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_notyfService.Error(ex.Message); | ||
return View(vm); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> Details(int id) | ||
{ | ||
try | ||
{ | ||
var book = await _bookRepository.GetBookWithUserAndCategory(id); | ||
var vm = new BookDetailsVm(){ | ||
Id = book.Id, | ||
Name = book.Name, | ||
Author = book.Author, | ||
Publication = book.Publication, | ||
NumberOfCopies = book.NumberOfCopies, | ||
AvailableCopies = book.AvailableCopies, | ||
Category = book.Category!.Name, | ||
CreatedDate = book.CreatedDate, | ||
CreatedBy = book.CreatedUser!.FullName, | ||
ModifiedDate = book.ModifiedDate, | ||
ModifiedBy = book.ModifiedUser?.FullName | ||
}; | ||
return View(vm); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_notyfService.Error(ex.Message); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.