private void DeleteEachBookCopy(List <BookCopyData> bookCopies, UserSessionObject user) { foreach (var item in bookCopies) { BookCopyRepository.DeleteById(item.Id, user.UserId); } }
public ActionResult ViewHistoryLoans() { UserSessionObject currentUser = Session.GetUser(); List <RelationUserBookCopyViewModel> activeLoans = LoanService.GetLoansForUser(false, currentUser.UserId); return(PartialView("Loans", activeLoans)); }
public DeleteBookResult DeleteCopy(int bookCopyId, UserSessionObject user) { var result = new DeleteBookResult(); BookCopyData bookCopyData = BookCopyRepository.GetDataById(bookCopyId); if (bookCopyData != null) { List <BookCopyData> list = new List <BookCopyData>() { bookCopyData }; if (CheckIfAnyCopyIsBorrowed(list)) { result.Message = "Book copy is currently borrowed. Can't be deleted."; } else { BookCopyRepository.DeleteById(bookCopyData.Id, user.UserId); BookData book = BookRepository.GetDataById(bookCopyData.BookId); book.NumOfAvailableCopies = book.NumOfAvailableCopies - 1; BookRepository.SaveData(book); result = new DeleteBookResult(book.Id, book.BookAuthorAndTitle, bookCopyData.Id); } } else { result.Message = "Please select book copy for delete."; } return(result); }
private bool CheckRoles(UserSessionObject currentUser) { bool result = false; result = currentUser.Roles.Any(x => RoleList.Any(y => y.Equals(x))); return(result); }
public SaveBookResult Save(BookCopyViewModel viewModel, UserSessionObject user) { var result = new SaveBookResult(); BookCopyDomainModelBuilder builder = BuilderResolverService.Get <BookCopyDomainModelBuilder, BookCopyViewModel>(viewModel); Constructor.ConstructDomainModelData(builder); BookCopyData domainModel = builder.GetDataModel(); if (viewModel.Id == 0) { domainModel.RefUserCreatedBy = user.UserId; } int id = BookCopyRepository.SaveData(domainModel); if (id != 0) { BookViewModel bookViewModel = Get(viewModel.BookId); bookViewModel.NumOfAvailableCopies = bookViewModel.NumOfAvailableCopies + 1; SaveBookResult updateResult = Save(bookViewModel, user); if (updateResult.Success) { result = new SaveBookResult(id, viewModel.BookAuthorAndTitle, "Successfully added copy of book " + viewModel.BookAuthorAndTitle); } } return(result); }
public BorrowResult BorrowBook(RelationUserBookCopyViewModel viewModel, UserSessionObject user) { var result = new BorrowResult(); viewModel.DateOfIssue = DateTime.Now; viewModel.DateDueForReturn = DateTime.Now.AddDays(14); RelationUserBookCopyDomainModelBuilder builder = BuilderResolverService.Get <RelationUserBookCopyDomainModelBuilder, RelationUserBookCopyViewModel>(viewModel); Constructor.ConstructDomainModelData(builder); RelationUserBookCopyData domainModel = builder.GetDataModel(); if (viewModel.Id == 0) { domainModel.RefUserCreatedBy = user.UserId; } int loanId = RelationUserBookCopyRepository.SaveData(domainModel); if (loanId != 0) { var saveResult = UpdateCopyAndBook(domainModel.BookCopyId, user); if (saveResult.Success) { string username = UserService.Get(domainModel.UserId).Username; result = new BorrowResult(loanId, domainModel.BookCopyId, username); } } return(result); }
private bool CheckPermissions(UserSessionObject currentUser) { bool result = false; result = currentUser.Permissions.Any(x => permissionsList.Any(y => y.Equals(x))); return(result); }
public SaveUserResult Save(UserViewModel viewModel, UserSessionObject currentUser) { var result = new SaveUserResult(); if (viewModel.IsNew) { viewModel.UserPassword = ConfigurationManager.AppSettings["DefaultPassword"]; } UserDomainModelBuilder builder = BuilderResolverService.Get <UserDomainModelBuilder, UserViewModel>(viewModel); Constructor.ConstructDomainModelData(builder); UserData domainModel = builder.GetDataModel(); if (viewModel.Id == 0) { domainModel.RefUserCreatedBy = currentUser.UserId; } int id = UserRepository.SaveData(domainModel); if (id != 0) { result = new SaveUserResult(id, domainModel.FullFirstAndLastName); } return(result); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { bool authorizeResult = false; UserSessionObject currentUser = (UserSessionObject)httpContext.Session[SessionConstant.USER]; if (currentUser != null) { if (RoleList.Count != 0 && permissionsList.Count != 0) { bool hasRole = CheckRoles(currentUser); bool hasPermission = CheckPermissions(currentUser); authorizeResult = hasRole || hasPermission; } else if (RoleList.Count == 0 && permissionsList.Count == 0) { authorizeResult = true; } else if (RoleList.Count != 0 && permissionsList.Count == 0) { authorizeResult = CheckRoles(currentUser); } else if (RoleList.Count == 0 && permissionsList.Count != 0) { authorizeResult = CheckPermissions(currentUser); } } else { authorizeResult = false; } return(authorizeResult); }
public ActionResult Delete(int id) { UserSessionObject user = Session.GetUser(); DeleteCategoryResult deleteResult = CategoryService.Delete(id, user); return(Json(deleteResult, JsonRequestBehavior.AllowGet)); }
public ActionResult Delete(int id) { UserSessionObject user = Session.GetUser(); DeleteBookResult result = BookService.DeleteCopy(id, user); return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult Delete(int id) { UserSessionObject user = Session.GetUser(); BookViewModel book = EBookService.Get(id); var relativePath = "~/UploadedFiles/" + book.Filename; var absolutePath = HttpContext.Server.MapPath(relativePath); bool result = EBookService.Delete(id, absolutePath, user.UserId); return(Json(new { Success = result }, JsonRequestBehavior.AllowGet)); }
public void Connect(UserSessionObject currentUser) { string connectionId = Context.ConnectionId; if (connectedChatUsers.Count(user => user.ConnectionId == connectionId) == 0) { if (connectedChatUsers.Count(user => user.UserId == currentUser.UserId) == 0) { ChatUser chatUser = new ChatUser(connectionId, currentUser.UserId, currentUser.Username, currentUser.Firstname, currentUser.Lastname); connectedChatUsers.Add(chatUser); } } }
public JsonResult Save(CategoryViewModel viewModel) { UserSessionObject user = Session.GetUser(); JsonResult response = (JsonResult)RouteData.Values["validation"]; ValidationResponse validation = (ValidationResponse)response.Data; if (validation.Success) { SaveCategoryResult result = CategoryService.Save(viewModel, user); response.Data = result; } return(response); }
public BookViewModel(EBookCreateViewModel ebookCreateViewModel, UserSessionObject user) { IsElectronic = true; Title = ebookCreateViewModel.Title; Author = ebookCreateViewModel.Author; PublicationYear = ebookCreateViewModel.PublicationYear; NumOfAvailableCopies = 0; Filename = ebookCreateViewModel.Filename; MIME = "application/pdf"; Keywords = ebookCreateViewModel.Keywords; LanguageId = ebookCreateViewModel.LanguageId; CategoryId = ebookCreateViewModel.CategoryId; CataloguerId = user.UserId; }
public ActionResult Borrow(RelationUserBookCopyViewModel viewModel) { UserSessionObject user = Session.GetUser(); JsonResult response = (JsonResult)RouteData.Values["validation"]; ValidationResponse validation = (ValidationResponse)response.Data; if (validation.Success) { viewModel.Id = 0; BorrowResult result = LoanService.BorrowBook(viewModel, user); response.Data = result; } return(response); }
public JsonResult GetAllActive(FilterSorterModel filterSorterModel) { UserSessionObject currentUser = Session.GetUser(); List <UserViewModel> userViewModels = UserService.GetAll(true); userViewModels.Remove(userViewModels.Single(x => x.Id == currentUser.UserId)); var filterSorter = new DataCollectionFilterSorter <UserViewModel>(); IEnumerable <UserViewModel> enumUserValuesViewModel = userViewModels.AsEnumerable(); enumUserValuesViewModel = filterSorter.FilterAndSort(enumUserValuesViewModel, filterSorterModel); return(Json(enumUserValuesViewModel, JsonRequestBehavior.AllowGet)); }
public void SetCurrentUser(HttpSessionStateBase session, HttpResponseBase response, LoginViewModel loginViewModel) { if (session[SessionConstant.USER] == null) { UserSessionObject currentUser = GenerateSessionObjectFor(loginViewModel.Username); session[SessionConstant.USER] = currentUser; if (loginViewModel.RememberMe) { HttpCookie cookie = new HttpCookie(SessionConstant.USERNAME); cookie.Expires = DateTime.Now.AddSeconds(3600); cookie.Value = loginViewModel.Username; response.Cookies.Add(cookie); } } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; UserSessionObject currentUser = (UserSessionObject)session[SessionConstant.USER]; if (currentUser == null) { RouteValueDictionary redirectValueDictionary = new RouteValueDictionary(); redirectValueDictionary.Add("action", "ShowNotAllowed"); redirectValueDictionary.Add("controller", "Home"); redirectValueDictionary.Add("area", ""); filterContext.Result = new RedirectToRouteResult(redirectValueDictionary); } base.OnActionExecuting(filterContext); }
public ActionResult Save(BookCopyViewModel viewModel) { UserSessionObject user = Session.GetUser(); JsonResult response = (JsonResult)RouteData.Values["validation"]; ValidationResponse validation = (ValidationResponse)response.Data; if (validation.Success) { viewModel.Id = 0; viewModel.Available = true; SaveBookResult result = BookService.Save(viewModel, user); response.Data = result; } return(response); }
private UserSessionObject GenerateSessionObjectFor(string username) { UserSessionObject currentUser = new UserSessionObject(); UserData user = UserRepository.GetUserByUsername(username); List <string> roles = GetRolesFor(username); List <string> permissions = GetPermissionsFor(username); currentUser.Username = username; currentUser.Email = user.Email; currentUser.UserId = user.Id; currentUser.Roles = roles; currentUser.Permissions = permissions; currentUser.Firstname = user.Firstname; currentUser.Lastname = user.Lastname; return(currentUser); }
public BorrowResult ReturnBook(int loandId, UserSessionObject user) { var result = new BorrowResult(); RelationUserBookCopyData loanData = RelationUserBookCopyRepository.GetDataById(loandId); if (loanData != null) { loanData.DateReturned = DateTime.Now; loanData.DateTimeDeletedOn = DateTime.Now; loanData.RefUserDeletedBy = user.UserId; loanData.IsActive = false; BookCopyData bookCopy = BookCopyRepository.GetDataById(loanData.BookCopyId); if (bookCopy != null) { bookCopy.OnLoan = false; BookData book = BookRepository.GetDataById(bookCopy.BookId); if (book != null) { book.NumOfAvailableCopies = book.NumOfAvailableCopies + 1; int bookId = BookRepository.SaveData(book); int bookCopyId = BookCopyRepository.SaveData(bookCopy); int loanId = RelationUserBookCopyRepository.SaveData(loanData); result = new BorrowResult(loandId, bookCopyId); } else { result.Message = "Book not found."; } } else { result.Message = "Book copy not found."; } } else { result.Message = "Loan with id " + loandId + "doesn't exist."; } return(result); }
private SaveBookResult UpdateCopyAndBook(int copyId, UserSessionObject user) { var result = new SaveBookResult(); BookCopyViewModel bookCopyData = BookService.GetCopy(copyId); bookCopyData.Available = false; result = BookService.SaveOnly(bookCopyData, user); if (result.Success) { BookViewModel bookData = BookService.Get(bookCopyData.BookId); bookData.NumOfAvailableCopies = bookData.NumOfAvailableCopies - 1; result = BookService.Save(bookData, user); } return(result); }
public DeleteBookResult Delete(int?bookId, UserSessionObject user) { var result = new DeleteBookResult(); if (bookId.HasValue) { DeleteBookResult deletingCopies = DeleteCopiesByBook(bookId.Value, user); if (deletingCopies.Success) { BookData domainModel = BookRepository.GetDataById(bookId.Value); if (domainModel != null) { BookRepository.DeleteById(bookId.Value, user.UserId); result = new DeleteBookResult(bookId.Value, domainModel.BookAuthorAndTitle); } } } return(result); }
public PermissionResult Assign(List <int> permissions, int userId, UserSessionObject currentUser) { bool flag = true; var wrongIds = new List <int>(); List <int> alreadyAssigned = RelationUserPermissionRepository .GetRelationUserPermissionFor(userId) .Select(x => x.PermissionId) .ToList(); PermissionResult result = null; foreach (int permissionId in permissions) { if (!alreadyAssigned.Contains(permissionId)) { var newLink = new RelationUserPermissionData { PermissionId = permissionId, UserId = userId, RefUserCreatedBy = currentUser.UserId }; RelationUserPermissionRepository.SaveData(newLink); } else { flag = false; wrongIds.Add(permissionId); } } if (!flag) { result = new PermissionResult(false, PermissionResult.OperationType.Assign, wrongIds); } else { result = new PermissionResult(true, PermissionResult.OperationType.Assign); } return(result); }
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; UserSessionObject currentUser = (UserSessionObject)session[SessionConstant.USER]; RouteValueDictionary redirectValueDictionary = new RouteValueDictionary(); redirectValueDictionary.Add("area", ""); if (currentUser != null) { redirectValueDictionary.Add("action", "Index"); redirectValueDictionary.Add("controller", "Home"); } else { redirectValueDictionary.Add("action", "Index"); redirectValueDictionary.Add("controller", "Account"); } filterContext.Result = new RedirectToRouteResult(redirectValueDictionary); }
public SaveCategoryResult Save(CategoryViewModel viewModel, UserSessionObject user) { var result = new SaveCategoryResult(); CategoryDomainModelBuilder builder = BuilderResolverService.Get <CategoryDomainModelBuilder, CategoryViewModel>(viewModel); Constructor.ConstructDomainModelData(builder); CategoryData domainModel = builder.GetDataModel(); if (viewModel.Id == 0) { domainModel.RefUserCreatedBy = user.UserId; } int id = CategoryRepository.SaveData(domainModel); if (id != 0) { result = new SaveCategoryResult(id, domainModel.NameCategory); } return(result); }
public ActionResult Create(EBookCreateViewModel viewModel) { var relativePath = "~/UploadedFiles/" + viewModel.Filename; var absolutePath = HttpContext.Server.MapPath(relativePath); SaveEBookResult result = null; UserSessionObject user = Session.GetUser(); if (System.IO.File.Exists(absolutePath)) { result = EBookService.SaveAndIndex(viewModel, absolutePath, user); } else { result = new SaveEBookResult() { Success = false, Message = "There is no file with given name. Please repeat upload!" }; } return(Json(result)); }
public DeleteCategoryResult Delete(int?categoryId, UserSessionObject user) { var result = new DeleteCategoryResult(); if (categoryId.HasValue) { if (!CheckReferencingBooks(categoryId.Value)) { CategoryData domainModel = CategoryRepository.GetDataById(categoryId.Value); if (domainModel != null) { CategoryRepository.DeleteById(categoryId.Value, user.UserId); result = new DeleteCategoryResult(categoryId.Value, domainModel.NameCategory); } } else { result.Message = "This category can't be deleted. There are books connected to this category."; } } return(result); }
public DeleteLanguageResult Delete(int?languageId, UserSessionObject user) { var result = new DeleteLanguageResult(); if (languageId.HasValue) { if (!CheckReferencingBooks(languageId.Value)) { LanguageData domainModel = LanguageRepository.GetDataById(languageId.Value); if (domainModel != null) { LanguageRepository.DeleteById(languageId.Value, user.UserId); result = new DeleteLanguageResult(languageId.Value, domainModel.NameLanguage); } } else { result.Message = "This language can't be deleted. There are books connected to this language."; } } return(result); }