public async Task <IActionResult> PutPublisher(int id, Publisher publisher) { if (id != publisher.PublisherId) { return(BadRequest()); } _context.Entry(publisher).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublisherExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBook(int id, Book book) { if (id != book.BookId) { return(BadRequest()); } _context.Entry(book).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAuthor(int id, Author author) { if (id != author.AuthorId) { return(BadRequest()); } //var id = author.AuthorId; _context.Entry(author).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("ID, StudentID, BookID, TakingDate")] BookTakenCreateVM bookTakenCreateVM) { if (ModelState.IsValid) { BookTaken issue = new BookTaken() { TakenBy = bookTakenCreateVM.StudentID, TakenBook = bookTakenCreateVM.BookID, TakingDate = bookTakenCreateVM.TakingDate }; _context.BookTaken.Add(issue); //await _context.SaveChangesAsync(); int bookID = issue.TakenBook; var bookToUpdate = await _context.Book .FirstOrDefaultAsync(s => s.ID == bookID); bookToUpdate.Quantity -= 1; if (await TryUpdateModelAsync <Book>( bookToUpdate, "Book", i => i.ID, i => i.Title, i => i.Author, i => i.Quantity)) { } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bookTakenCreateVM)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public virtual async Task <bool> DeleteAsync(Tkey id) { var result = await _dbSet.SingleOrDefaultAsync(e => e.Id.Equals(id)); if (result == null) { return(false); } _dbSet.Remove(result); await _db.SaveChangesAsync(); return(true); }
public async Task <IActionResult> PutLibraryUserRegistrationRequest(int id, LibraryUserRegistrationRequest libraryUserRegistrationRequest) { if (id != libraryUserRegistrationRequest.RequestId) { return(BadRequest()); } _context.Entry(libraryUserRegistrationRequest).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LibraryUserRegistrationRequestExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> RegisterAccount([Bind("FirstName,LastName,Nidno,PassportNo,Email,MobileNo,HomeAddress,City,Country,DateOfBirth,Uname,Upassword,ConfirmPassword")] LibraryUserRegistrationRequest libraryUserRequest) { //Model validation if (ModelState.IsValid) { string message = null; #region Custom Model Validation //validate Date Of Birth if (string.IsNullOrEmpty(libraryUserRequest.DateOfBirth)) { ModelState.AddModelError( "DateOfBirth", "You must provide your Date Of Birth"); return(View(libraryUserRequest)); } //Email verify: active user var userWithEmail = await _context.LibraryUser. FirstOrDefaultAsync( a => a.Email == libraryUserRequest.Email && a.AccountStatus == "Active"); if (userWithEmail != null) { ModelState. AddModelError( "Email", "There is already a member account with mailing address"); return(View(libraryUserRequest)); } //Email verify: active user request var userRequestWithEmail = await _context. LibraryUserRegistrationRequest. FirstOrDefaultAsync( a => a.Email == libraryUserRequest.Email && (a.UserRequestStatus != "New" || a.UserRequestStatus == "Email Veified")); if (userRequestWithEmail != null) { ModelState. AddModelError( "Email", "There is already a pending membership request for this mailing address"); return(View(libraryUserRequest)); } //Email verify: rejected in last three months var rejectedInthreeMonth = await _context.LibraryUserRegistrationRequest.FirstOrDefaultAsync( a => (a.Email == libraryUserRequest.Email || a.Nidno == libraryUserRequest.Nidno || a.PassportNo == libraryUserRequest.PassportNo) && a.UserRequestStatus == "Reject" && a.RequestTime >= DateTime.Now.AddMonths(-3)); if (rejectedInthreeMonth != null) { ViewBag.Status = true; message = "Libarry Membership Request for " + libraryUserRequest.FirstName + " " + libraryUserRequest.LastName + " " + "has been rejected less then three months ago. We can not receive your application now." + " Please try again later"; ViewBag.Message = message; return(View(libraryUserRequest)); } //check unique username var resultUser = await _context. LibraryUser. FirstOrDefaultAsync( a => a.Uname == libraryUserRequest.Uname); var resultUserRequest = await _context. LibraryUserRegistrationRequest. FirstOrDefaultAsync( a => a.Uname == libraryUserRequest.Uname && (a.UserRequestStatus != "New" || a.UserRequestStatus == "Email Verified")); if (resultUser != null || resultUserRequest != null) { ModelState. AddModelError("Uname", "User Name is not available. Please select a different User Name"); return(View(libraryUserRequest)); } #endregion #region Add Request //generate activation code libraryUserRequest.ActivationCode = System.Guid.NewGuid().ToString(); //Password Hashing libraryUserRequest.Upassword = CryptoHelper.Hash(libraryUserRequest.Upassword); //Set datetime libraryUserRequest.RequestTime = System.DateTime.Now; libraryUserRequest.UserRequestStatus = "New"; //Save Request _context.LibraryUserRegistrationRequest.Add(libraryUserRequest); await _context.SaveChangesAsync(); #endregion #region Send Email //Send email to user //SendEmailWithVerificationString(libraryUserRequest.Email, libraryUserRequest.ActivationCode); ViewBag.Status = true; message = "Libarry Membership Request for " + libraryUserRequest.FirstName + " " + libraryUserRequest.LastName + " " + "is successfully placed. To Verify request please check your mail for activation link." + " if you fail to activate with in 3 days your activation link will expire"; ViewBag.Message = message; #endregion return(View(libraryUserRequest)); } return(View(libraryUserRequest)); }