/// <summary> /// Visualize the resume. /// </summary> public IActionResult ViewResume() { var resumeDto = this.resumeService.OpenResume(); var resume = mapper.MapTo <ResumeViewModel>(resumeDto); return(this.View(resume)); }
public async Task <BankDetailsViewModel> AddBankDetailsAsync(string number, int cvv, DateTime expiryDate, string userId) { int dateResult = DateTime.Compare(expiryDate, dateTime.Now()); if (dateResult < 0) { throw new ArgumentOutOfRangeException("The card is expired!"); } var potentialBankDetails = await bankDetailsRepo.All().Where(bd => bd.Number == number).FirstOrDefaultAsync(); if (!(potentialBankDetails is null)) { var potentialUserBankDetails = await userBankDetailsRepo.All() .Where(ubd => ubd.UserId == userId && ubd.BankDetailsId == potentialBankDetails.Id) .FirstOrDefaultAsync(); if (potentialUserBankDetails is null) { throw new ArgumentException("The card is already being used!"); } if (potentialUserBankDetails.IsDeleted) { potentialUserBankDetails.IsDeleted = false; await userBankDetailsRepo.SaveAsync(); var modelToReturn = mappingProvider.MapTo <BankDetailsViewModel>(potentialBankDetails); return(modelToReturn); } else { throw new ArgumentException("Bank details already exists and it is connected to the user!"); } } var bankDetails = new BankDetails { Number = number, Cvv = cvv, ExpiryDate = expiryDate, CreatedOn = DateTime.Now, IsDeleted = false, UserBankDetails = new List <UserBankDetails>() }; bankDetailsRepo.Add(bankDetails); var userBankDetails = new UserBankDetails { UserId = userId, BankDetailsId = bankDetails.Id }; bankDetails.UserBankDetails.Add(userBankDetails); await bankDetailsRepo.SaveAsync(); var model = mappingProvider.MapTo <BankDetailsViewModel>(bankDetails); return(model); }
public void Add(UserTestDto dto) { Guard.WhenArgument(dto, "UserTestDto").IsNull().Throw(); var test = mapper.MapTo <UserTest>(dto); userTests.Add(test); saver.SaveChanges(); }
public TwitterUserDto GetTwitterUserById(string twitterUserId) { if (string.IsNullOrEmpty(twitterUserId)) { return null; } var twitterUser = twitterUsers.All.SingleOrDefault(x => x.TwitterId == twitterUserId); return mapper.MapTo<TwitterUserDto>(twitterUser); }
public TweetDto GetTweetById(string tweetId) { if (string.IsNullOrEmpty(tweetId)) { return(null); } var tweet = tweets .All .SingleOrDefault(x => x.Id == tweetId); return(mappingProvider.MapTo <TweetDto>(tweet)); }
/// <summary> /// Creates a new test and directly publishes it. /// </summary> /// <param name="testDto">Test dto to publish.</param> public void Publish(TestDto testDto) { if (testDto == null) { throw new InvalidTestException("Test dto cannot be null!"); } var test = mapper.MapTo <Test>(testDto); test.StatusId = 1; // Published tests.Add(test); saver.SaveChanges(); }
public void AddCourseToStudent(Guid courseId, string studentId) { Guard.WhenArgument(studentId, "StudentId can not be null!").IsNullOrWhiteSpace().Throw(); var studentCourseDto = new StudentCourseDto() { StudentId = studentId, CourseId = courseId }; var studentCourse = mapper.MapTo <StudentCourse>(studentCourseDto); Guard.WhenArgument(studentCourse, "Student Course can not be null!").IsNull().Throw(); var checkIfObjectAlreadyExists = this.studentCourses.AllAndDeleted .FirstOrDefault(sc => sc.CourseId == courseId && sc.StudentId == studentId); if (checkIfObjectAlreadyExists != null) { checkIfObjectAlreadyExists.IsDeleted = false; } else { this.studentCourses.Add(studentCourse); } this.saver.SaveChanges(); }
public async Task <BankDetailsViewModel> DeleteUserBankDetailsAsync(string bankDetailsId, string userId) { if (userId is null) { throw new ArgumentNullException("UserId cannot be null!"); } if (bankDetailsId is null) { throw new ArgumentNullException("BankDetailsId cannot be null!"); } var userBankDetailsToRemove = await userBankDetailsRepo.All() .Include(ubd => ubd.User) .Include(ubd => ubd.BankDetails) .Where(ubd => ubd.UserId == userId && ubd.BankDetailsId.ToString() == bankDetailsId) .FirstOrDefaultAsync(); if (userBankDetailsToRemove is null) { throw new ArgumentException("UserBankDetails not found!"); } var bankDetails = userBankDetailsToRemove.BankDetails; userBankDetailsToRemove.IsDeleted = true; await userBankDetailsRepo.SaveAsync(); return(mappingProvider.MapTo <BankDetailsViewModel>(bankDetails)); }
public TestDTO GetRandomTestFromCategory(Guid categoryID) { // test status should be published and test shouldnt be deleted var testsFromThisCategory = tests.All.Where(test => test.CategoryId == categoryID && test.Status == TestStatus.Published && !test.IsDeleted). Include(t => t.Questions). ThenInclude(x => x.Answers) .ToList(); if (testsFromThisCategory.Count() < 1) { throw new CategoryEmptyException(); } var randomTest = testsFromThisCategory[this.random.GiveMeRandomNumber(testsFromThisCategory.Count())]; var randomTestDto = mapper.MapTo <TestDTO>(randomTest); return(randomTestDto); }
public async Task <ICollection <UserViewModel> > SearchByUsernameAsync(string username) { List <User> users; if (username is null) { users = await userRepo.All().ToListAsync(); } else { users = await userRepo.All().Where(u => u.UserName.ToLower() .Contains(username.ToLower())) .ToListAsync(); } var models = mappingProvider.MapTo <ICollection <UserViewModel> >(users); return(models); }
private UserTestsDTO GetUserTest(string email, Guid testId) { var userTest = this.userTests.All.Where(ut => ut.User.Email == email && ut.TestId == testId). Include(ut => ut.Test). ThenInclude(t => t.Questions). ThenInclude(q => q.Answers). First(); var userTestDto = mapper.MapTo <UserTestsDTO>(userTest); return(userTestDto); }
//public void Edit(AnswerDto answer) //{ // Answer answerToEdit = answers.All. // FirstOrDefault(a => a.Id == answer.Id) // ?? throw new ArgumentNullException("Answer can not be null."); // answerToEdit.Content = answer.Content; // answerToEdit.QuestionId = answer.QuestionId; // answerToEdit.IsCorrect = answer.IsCorrect; // answers.Update(answerToEdit); // saver.SaveChanges(); //} //public void Delete(int id) //{ // var answerToDelete = answers.All // .FirstOrDefault(a => a.Id == id) // ?? throw new ArgumentNullException("Answer can not be null."); // answers.Delete(answerToDelete); //} public AnswerDto GetById(int id) { var currentAnwer = answers.All .FirstOrDefault(answer => answer.Id == id) ?? throw new ArgumentNullException("Answer can not be Null."); var dto = mapper.MapTo <AnswerDto>(currentAnwer) ?? throw new ArgumentNullException("AnswerDto can not be Null."); return(dto); }
//public IEnumerable<TestDto> GetCategoryTests(int categoryId) //{ // var testsInCategory = categories.All // .Where(c => c.Id == categoryId) // .Include(c => c.Tests) ?? throw new ArgumentNullException("Collection of tests in category is null"); // return mapper.ProjectTo<TestDto>(testsInCategory); //} public CategoryDto GetCategoryByName(string name) { Guard.WhenArgument(name, "Category Name").IsNullOrEmpty().Throw(); var category = categories.All.Where(c => c.Name == name).FirstOrDefault() ?? throw new ArgumentNullException("Category not found!"); var dto = mapper.MapTo <CategoryDto>(category) ?? throw new ArgumentNullException("CategoryDto can not be null."); return(dto); }
public TestDTO GetTestByName(string name) { var test = this.testRepository.All .Where(x => x.Name == name) .Include(x => x.Questions) .ThenInclude(x => x.Answers) .FirstOrDefault(); var testDTO = mapper.MapTo <TestDTO>(test); return(testDTO); }
public Tweet CreateFromApiDto(TweetFromApiDto tweet) { if (tweet == null) { throw new ArgumentNullException("Tweet cannot be null!"); } var tweetToAdd = mapper.MapTo <Tweet>(tweet); this.unitOfWork.Tweets.Add(tweetToAdd); this.unitOfWork.SaveChanges(); return(tweetToAdd); }
public async Task <TransactionViewModel> CreateTransactionAsync(TypeOfTransaction type, string description, decimal amount, string userId) { var balance = await balanceRepo.All() .Include(b => b.User) .Include(b => b.Type) .Where(b => b.UserId == userId && b.Type.Name == BalanceTypes.Base.ToString()) .FirstOrDefaultAsync(); if (balance is null) { throw new ArgumentNullException("Balance can`t be null"); } var transactionType = await transactionTypeRepo.All() .Where(t => t.Name.ToLower() == type.ToString().ToLower()) .FirstOrDefaultAsync(); if (transactionType is null) { throw new ArgumentNullException("Transaction type can`t be null"); } var transaction = new Transaction { Type = transactionType, Balance = balance, Date = DateTime.Now, Description = description, Amount = amount, OpeningBalance = balance.Money - amount }; transactionRepo.Add(transaction); await transactionRepo.SaveAsync(); var model = mappingProvider.MapTo <TransactionViewModel>(transaction); return(model); }
public ICollection<TwitterUserDto> GetUserFavourites(string userId) { if (userId.IsNullOrWhitespace()) { throw new InvalidUserIdException(nameof(userId)); } var favourites = userTwitterUsers .All .Where(x => x.UserId.Equals(userId)) .Select(x => x.TwitterUser); return mapper.MapTo<List<TwitterUserDto>>(favourites); }
public IActionResult ShowTest(string id) //beneath is the category name not id !! { try { var category = id; var userId = userService.GetLoggedUserId(this.User); var correctUserTestDto = userTestsService.GetCorrectSolveTest(userId, category); var correctUserTestView = mapper.MapTo <SolveTestViewModel>(correctUserTestDto); return(View(correctUserTestView)); } catch (CategoryDoneException) { return(this.RedirectToAction("CategoryDone", "Solve")); } catch (TimeUpNeverSubmittedException) { return(this.RedirectToAction("TimeUpNotSubmitted", "Solve")); } catch (CategoryEmptyException) { return(this.RedirectToAction("CategoryEmpty", "Solve")); } }
public async Task <IActionResult> Index(string id) { var user = await this.userManager.GetUserAsync(HttpContext.User); StatusType check = resultService.CheckForTakenTest(user.Id, id); TestDto testDto = null; var startTime = DateTime.Now; if (check == StatusType.TestSubmitted) { return(RedirectToAction("Index", "Dashboard")); } if (check == StatusType.TestNotSubmitted) { testDto = this.resultService.GetTestFromCategory(user.Id, id); startTime = (DateTime)resultService.GetUserTest(user.Id, testDto.Id).StartTime; } else { testDto = this.testService.GetRandomTestByCategory(id); } var questions = mapper.ProjectTo <QuestionViewModel>(testDto.Questions.AsQueryable()).ToList(); var model = new IndexViewModel() { UserId = user.Id, TestId = testDto.Id, TestName = testDto.TestName, Duration = testDto.Duration, CategoryName = id, Questions = questions, StartedOn = startTime }; if (check == StatusType.TestNotStarted) // move to service { var resultDto = mapper.MapTo <UserTestDto>(model); resultDto.Id = Guid.NewGuid(); resultService.AddResult(resultDto); this.saver.SaveChanges(); } return(View(model)); }
public UserTestDTO GetAssignedTestWithCategory(string category) { var userId = this.userService.GetCurrentLoggedUser(); var userTest = userTestRepository.All .Where(x => x.UserId == userId) .Include(x => x.Test.Category) .Include(x => x.Test) .ThenInclude(x => x.Questions) .ThenInclude(x => x.Answers) .Where(x => x.Test.Category.Name == category) .FirstOrDefault(); var dto = mapper.MapTo <UserTestDTO>(userTest); return(dto); }
public TestSolutionDTO GetDetailedSolution(string userEmail, Guid testId) { var userTest = userTests.All.Where(ut => ut.TestId == testId && ut.User.Email == userEmail) .Include(ut => ut.Test) .ThenInclude(t => t.Questions) .ThenInclude(q => q.Answers) .Include(ut => ut.Answers) .ThenInclude(uta => uta.Answer) .First(); var userTestAnswers = userTest.Answers; var testSolutionDto = mapper.MapTo <TestSolutionDTO>(userTest); testSolutionDto.QuestionAnswers = new Dictionary <Guid, Guid>(); foreach (var uta in userTestAnswers) { testSolutionDto.QuestionAnswers.Add(uta.Answer.QuestionId, uta.Answer.Id); } return(testSolutionDto); }
public IActionResult All() { if (User.IsInRole("Admin")) { return(RedirectToAction("Index", "Dashboard", new { Area = "Administration" })); } var userId = this.userManager.GetUserId(HttpContext.User); var categories = this.categories.GetAll(); var model = new DashboardViewModel() { Categories = this.mapper.ProjectTo <CategoryViewModel>(categories).ToList(), }; foreach (var category in model.Categories) { var randomTest = tests.GetRandomTestByCategory(category.Name, userId); category.Test = mapper.MapTo <TestViewModel>(randomTest); } return(View(model)); }