public ActionResult AddNewComment(MultipleModel.CommentsVM request) { var errorList = new List <string>(); if (ModelState.IsValid) { var getUser = db.Users.Where(u => u.Id == request.NewComment.UserId && u.Deleted == false).SingleOrDefault(); if (getUser != null) { var getBook = db.Books.Where(b => b.Id == request.NewComment.BookId && b.Delete == false).SingleOrDefault(); if (getBook != null) { if (!(db.Comments.Where(c => c.UserId == getUser.Id && c.BookId == getBook.Id).Where(c => c.Comment.ToLower() == request.NewComment.Comment.ToLower()).Any())) { var newComment = db.Comments.Create(); newComment.Book = getBook; newComment.User = getUser; newComment.Comment = request.NewComment.Comment; newComment.CreatedAt = DateTime.UtcNow; db.Comments.Add(newComment); db.SaveChanges(); ModelState.Clear(); request.Error = false; string message = "You have successfully add a new comment"; errorList.Add(message); request.Message = errorList; } else if (db.Comments.Where(c => c.UserId == getUser.Id && c.BookId == getBook.Id).Where(c => c.Comment.ToLower() == request.NewComment.Comment.ToLower()).Any()) { request.Error = true; string message = "Duplicate comments are not allowed!!"; errorList.Add(message); request.Message = errorList; } } else if (getBook == null) { request.Error = true; string message = "The selected book is not existing!!"; errorList.Add(message); request.Message = errorList; } } else if (getUser == null) { request.Error = true; string message = "Invalid user!! Kindly sign in again"; errorList.Add(message); request.Message = errorList; } } else if (!(ModelState.IsValid)) { request.Error = true; request.Message = CustomValidationMessage.GetErrorList(ViewData.ModelState); } request.Book = db.Books.Where(b => b.Id == request.NewComment.BookId && b.Delete == false).SingleOrDefault(); return(PartialView("_ViewBookComment", request)); }
public ActionResult ActivateAccount2(MultipleModel.AuthModelVM request) { if (ModelState.IsValid) { using (var db = new LibraryDbContext()) { MultipleModel.AuthModelVM vm = new MultipleModel.AuthModelVM(); vm.UserModel = db.Users.SingleOrDefault(u => u.Id == request.UserModel.Id); var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(request.ActivationModel1.Password); vm.UserModel.PasswordSalt = crypto.Salt; vm.UserModel.Password = encrypPass; vm.UserModel.SecretQuestion = request.ActivationModel1.SecretQuestion; vm.UserModel.SecretAnswer = request.ActivationModel1.SecretAnswer; vm.UserModel.Status = true; vm.UserModel.Deleted = false; vm.UserModel.UpdatedAt = DateTime.UtcNow; vm.UserModel.Student.Birthday = request.ActivationModel1.Birthday; vm.UserModel.Student.StudentAddress = new LibraryDbContext.StudentAddressModel { ZipCode = request.ActivationModel1.ZipCode, Address1 = request.ActivationModel1.Address1, Address2 = request.ActivationModel1.Address2, City = request.ActivationModel1.City, Country = request.ActivationModel1.Country, CreatedAt = DateTime.UtcNow, }; db.Entry(vm.UserModel).State = EntityState.Modified; db.SaveChanges(); var ctx = Request.GetOwinContext(); var authManager = ctx.Authentication; authManager.SignOut("ApplicationCookie"); var loginVM = new MultipleModel.LoginModelVM(); loginVM.Error = false; var errorList = new List <string>(); string message = "You have successfully activated your account. Please log in"; errorList.Add(message); loginVM.Message = errorList; TempData["LoginTD"] = loginVM; return(RedirectToAction("Login")); } } request.Error = true; request.Message = CustomValidationMessage.GetErrorList(ViewData.ModelState); TempData["UserActivation"] = request; return(RedirectToAction("ActivateAccount2", new { id = request.UserModel.Id })); }
public ActionResult RecommendBook(MultipleModel.RecommendBookVM req) { var model = new MultipleModel.RecommendBookVM(); var messageList = new List <string>(); var identity = (System.Security.Claims.ClaimsIdentity)User.Identity; var getUserId = identity.Claims.Where(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier).Select(c => c.Value).SingleOrDefault(); model.Error = true; if (ModelState.IsValid) { var getUser = db.Users.Where(u => u.Email == req.Recommend.Email).Where(u => u.Deleted == false).SingleOrDefault(); if (getUser != null) { if (!(db.BookRecommendations.Where(b => b.FromUserId == new Guid(getUserId)).Where(b => b.ToUserId == getUser.Id).Where(b => b.BookId == req.Recommend.BookId).Where(b => b.Deleted == false).Any())) { var newRecommend = db.BookRecommendations.Create(); newRecommend.BookId = req.Recommend.BookId; newRecommend.ToUserId = getUser.Id; newRecommend.FromUserId = new Guid(getUserId); newRecommend.CreatedAt = DateTime.UtcNow; newRecommend.Deleted = false; db.BookRecommendations.Add(newRecommend); db.SaveChanges(); string message = "You have successfully recommend this book to " + getUser.Email; model.Error = false; messageList.Add(message); } else { string message = "You have already recommended this book to " + req.Recommend.Email; messageList.Add(message); } } else { string message = "The user is not existing!!"; messageList.Add(message); } } else { messageList = CustomValidationMessage.GetErrorList(ViewData.ModelState); } model.Message = messageList; model.Book = db.Books.Where(b => b.Id == req.Recommend.BookId).Where(b => b.Delete == false).SingleOrDefault(); return(PartialView("_RecommendBookForm", model)); }