예제 #1
0
        public async Task <IActionResult> Login(LoginDTO input)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = string.Join("; ", ModelState.Values
                                               .SelectMany(x => x.Errors)
                                               .Select(x => x.ErrorMessage));
                    throw new Exception("Please correct the following errors: " + Environment.NewLine + messages);
                }

                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result =
                    await _signInManager.PasswordSignInAsync(input.Username, input.Password, input.RememberMe, false);

                if (result.Succeeded)
                {
                    var person = _lookUpService.GetPersonDetailsByUsername(input.Username).Result;

                    var user = await _userManager.Users.FirstOrDefaultAsync(a => a.UserName.Equals(input.Username));

                    var userRole = await _userManager.GetRolesAsync(user);

                    if (userRole.ToList()[0].Equals(Const.ADMINISTRATOR_USER))
                    {
                        return(RedirectToRoute("", new { controller = "Dashboard", action = "Index" }));
                    }

                    if (person == null)
                    {
                        _notyf.Warning("User logged out successful...", 10);
                        return(RedirectToRoute("", new { controller = "Person", action = "CreateAccount" }));
                    }

                    _notyf.Success("Login was successful", 10);
                    return(RedirectToRoute("", new { controller = "Person", action = "Details", Id = person.NationalID }));
                }

                _notyf.Error("Login for " + input.Username + " failed...", 10);

                return(View(input));
            }
            catch (Exception ex)
            {
                _notyf.Error("Something went wrong...");
                return(Json(new { Result = "ERROR", ex.Message }));
            }
        }
예제 #2
0
 public IActionResult Index()
 {
     try
     {
         _user        = _data.GetUserAsync(TempData["user"] as string).Result;
         ViewBag.User = _user;
         return(View());
     }
     catch
     {
         _notyf.Warning("Login once again");
         return(RedirectToAction("Index", "Home"));
     }
 }
예제 #3
0
        private void UpdateWalletBalances(Transaction transaction)
        {
            // Update balance of receiving wallet
            string UpdateAddressTo = transaction.ToAddress;

            var receivingWallet = (
                from w in _context.Wallets
                where w.publicAddress == UpdateAddressTo
                select w).FirstOrDefault();

            if (transaction.Processed == true)
            {
                receivingWallet.Balance += transaction.Amount;
                _context.Update(receivingWallet);
                _context.SaveChanges();
            }
            else
            {
                _notyf.Warning("Transaction not yet processed, RECEIVING wallet will not be updated.");
            }

            // Update balance of sending wallet
            if (transaction.FromAddress == null)
            {
                _notyf.Information("There is no From Address, updating of From Address is skipped.");
            }
            else
            {
                string UpdateAddressFrom = transaction.FromAddress;

                var sendingWallet = (
                    from w in _context.Wallets
                    where w.publicAddress == UpdateAddressFrom
                    select w).FirstOrDefault();

                if (transaction.Processed == true)
                {
                    sendingWallet.Balance -= transaction.Amount;
                    _context.Update(sendingWallet);
                    _context.SaveChanges();
                }
                else
                {
                    _notyf.Warning("Transaction not yet processed, SENDING wallet will not be updated.");
                }
            }
            _notyf.Information("Wallet balances updated.");
        }
예제 #4
0
        public async Task <IActionResult> CheckBalance()
        {
            System.Security.Claims.ClaimsPrincipal currentUser = User;
            var UserId = _userManager.GetUserId(currentUser);
            // Reference logged in User
            ApplicationUser LoggedInUser = await _userManager.FindByIdAsync(UserId);

            var walletAddress = (
                from w in _context.Wallets
                where w.Username == LoggedInUser.UserName
                select w.publicAddress).FirstOrDefault();

            if (walletAddress != null)
            {
                var walletBalance = (
                    from w in _context.Wallets
                    where w.Username == LoggedInUser.UserName
                    select w.Balance).FirstOrDefault();

                _notyf.Information($"Your wallet balance is: {walletBalance}");
            }
            else
            {
                _notyf.Warning("No wallet balance recorded!", 10);
            }

            var wallet = (from w in _context.Wallets
                          where w.Username == LoggedInUser.UserName
                          select w).FirstOrDefault();

            ViewBag.walletAddress = walletAddress;
            return(View("Wallet", wallet));
        }
예제 #5
0
 public IActionResult Index()
 {
     _notyf.Success("Success Notification");
     _notyf.Success("Success Notification that closes in 10 Seconds.", 3);
     _notyf.Error("Some Error Message");
     _notyf.Warning("Some Error Message");
     _notyf.Information("Information Notification - closes in 4 seconds.", 4);
     _notyf.Custom("Custom Notification - closes in 5 seconds.", 5, "whitesmoke", "fa fa-gear");
     _notyf.Custom("Custom Notification - closes in 5 seconds.", 10, "#B600FF", "fa fa-home");
     return(View());
 }
예제 #6
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,Category,UnitPrice,StockQty")] Products products)
        {
            if (ModelState.IsValid)
            {
                _context.Add(products);
                await _context.SaveChangesAsync();

                await _hub.Clients.All.SendAsync("LoadProducts");

                _notyf.Custom("Create Succussfully- closes in 5 seconds.", 5, "whitesmoke", "fa fa-gear");
                _notyf.Success("Success that closes in 10 Seconds.", 3);
                return(RedirectToAction(nameof(Index)));
            }
            _notyf.Warning("Some Error Message");
            return(View(products));
        }
예제 #7
0
        public async Task<IActionResult> CreateAccount([Bind("Person", "Address", "Photo", "Learner", "Cv")] LearnerViewModel learnerViewModel)
        {
            if (ModelState.IsValid)
            { 
                // This Uploads learner profile image
                var photoPath =  _fconfig.Images  + learnerViewModel.Person.NationalId + "/" + Utils.GenerateImageFolderId() + "/";
               
                if (learnerViewModel.Photo != null)
                { 
                   _fileService.UploadFile( learnerViewModel.Photo,_env.WebRootPath + photoPath);    
                    
                   learnerViewModel.Person.PhotoName = learnerViewModel.Photo.FileName; 
                   learnerViewModel.Person.PhotoPath = photoPath;
                   Console.WriteLine(" FILE NAME : " + learnerViewModel.Photo.FileName); 
                }
                
                var cvPath =  _fconfig.Documents  + learnerViewModel.Person.NationalId + "/" + Utils.GenerateDocsFolderId() + "/";

                if (learnerViewModel.Cv != null)
                { 
                    _fileService.UploadFile( learnerViewModel.Cv,_env.WebRootPath + cvPath);    
                    
                    learnerViewModel.Person.CvName = learnerViewModel.Cv.FileName; 
                    learnerViewModel.Person.CvPath = cvPath;
                    Console.WriteLine(" FILE NAME : " + learnerViewModel.Cv.FileName); 
                }
  
                learnerViewModel.Person.CreatedBy = "admin";
                learnerViewModel.Person.DateCreated = DateTime.Now; 

                learnerViewModel.Person.LastUpdatedBy = "admin";
                learnerViewModel.Person.DateUpdated = DateTime.Now;
                
                learnerViewModel.Address.CreatedBy = "admin";
                learnerViewModel.Address.DateCreated = DateTime.Now;

                learnerViewModel.Address.LastUpdatedBy = "admin";
                learnerViewModel.Address.DateUpdated = DateTime.Now;
                            
                learnerViewModel.Learner.CreatedBy = "admin";
                learnerViewModel.Learner.DateCreated = DateTime.Now;
 
                learnerViewModel.Learner.LastUpdatedBy = "admin";
                learnerViewModel.Address.DateUpdated = DateTime.Now;
                
                learnerViewModel.Learner.AppliedYn = Const.FALSE;
                learnerViewModel.Learner.RecruitedYn = Const.FALSE;
                
                //Link the Address to the Person     
                learnerViewModel.Person.Address.Add(learnerViewModel.Address); 

                // Add the Person into the Database
                var user = await _lookUpService.GetUserByUsrname(User.Identity.Name);

                learnerViewModel.Person.UserId = user.Id;
                learnerViewModel.Person.Email = user.Email;
                
                //Now link the learner to this Person Profile created 
                learnerViewModel.Learner.Person = learnerViewModel.Person;

                //Then Add the Company

                //Then Add the Learner to the Database     
                _context.Add(learnerViewModel.Learner);
 
                //Save the Person and Address in to the Database
                await _context.SaveChangesAsync();
                _notyf.Warning("Profile created successful...", 5);
                
                ViewData["CitizenshipStatusId"] = new SelectList(_context.CitizenshipStatus, "CitizenshipStatusId", "CitizenshipStatusDesc",learnerViewModel.Person.CitizenshipStatusId);
                ViewData["DisabilityStatusId"] = new SelectList(_context.DisabilityStatus, "DisabilityStatusId", "DisabilityStatusDesc",learnerViewModel.Person.DisabilityStatusId);
                ViewData["EquityId"] = new SelectList(_context.Equity, "EquityId", "EquityDesc",learnerViewModel.Person.EquityId);
                ViewData["GenderId"] = new SelectList(_context.Gender, "GenderId", "GenderDesc",learnerViewModel.Person.GenderId);
                ViewData["HomeLanguageId"] = new SelectList(_context.HomeLanguage, "HomeLanguageId", "HomeLanguageDesc",learnerViewModel.Person.HomeLanguageId);
                ViewData["NationalityId"] = new SelectList(_context.Nationality, "NationalityId", "NationalityDesc",learnerViewModel.Person.NationalityId);
                ViewData["SuburbId"] = new SelectList(_lookUpService.GetSuburbs().Result, "id", "name",learnerViewModel.Address.SuburbId);
                ViewData["CityId"] = new SelectList(await _lookUpService.GetCities(), "id", "name",learnerViewModel.Address.CityId);
                ViewData["ProvinceId"] = new SelectList(_lookUpService.GetProvinces().Result, "id", "name",learnerViewModel.Address.ProvinceId);
                ViewData["CountryId"] = new SelectList(_lookUpService.GetCountries().Result, "id", "name",learnerViewModel.Address.CountryId);
                ViewData["AddressTypeId"] = new SelectList(_lookUpService.GetAddressTypes().Result, "id", "name",learnerViewModel.Person.CitizenshipStatusId);
                /*ViewData["InstitutionId"] = new SelectList(_lookUpService.GetInstitutions().Result, "id", "name",learnerViewModel.Learner.);
                ViewData["CourseId"] = new SelectList(_lookUpService.GetCourses().Result, "id", "name",learnerViewModel.Person.CitizenshipStatusId);*/
                ViewData["SchoolId"] = new SelectList(_lookUpService.GetSchools().Result, "id", "name",learnerViewModel.Learner.SchoolId);
                ViewData["SchoolGradeId"] = new SelectList(_lookUpService.GetSchoolGrades().Result, "id", "name",learnerViewModel.Learner.SchoolGradeId); 
                return RedirectToAction(nameof(Details), new { id = learnerViewModel.Person.NationalId });
            }

            return View();
        }