Exemple #1
0
        public async Task <IActionResult> Create([Bind("ID,Email,Password")] Users users)
        {
            user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
            bool AlreadyExist = _context.Users.Any(u => u.Email == users.Email);

            if (AlreadyExist)
            {
                ViewBag.AlreadyExist = true;
                return(View("~/Views/Users/Create.cshtml"));
            }
            if (user == null)
            {
                if (ModelState.IsValid)
                {
                    users.Password = getHash(users.Password);
                    _context.Add(users);
                    await _context.SaveChangesAsync();

                    var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role);
                    identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, users.Email));
                    identity.AddClaim(new Claim(ClaimTypes.Name, users.Email));

                    // Authenticate using the identity
                    var principal = new ClaimsPrincipal(identity);
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
                }
                return(RedirectToAction("Index", "Tours"));
            }
            else
            {
                return(View("~/Views/Home/Index.cshtml"));
            }
        }
        public async Task <bool> AddCounter(Counter counterDetails)
        {
            counterDetails.CreatedOn = DateTime.Now;
            _travelContext.Add(counterDetails);
            var result = await _travelContext.SaveChangesAsync();

            return(result > 0);
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("ID,ClientName")] Clients clients)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clients);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clients));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("ID,ExcursionName")] Excursion_Sights excursion_Sights)
        {
            if (ModelState.IsValid)
            {
                _context.Add(excursion_Sights);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(excursion_Sights));
        }
Exemple #5
0
        public int RegisterUser(RegisterUser registerUser)
        {
            var entity = new User {
                FirstName = registerUser.FirstName,
                Email     = registerUser.Email,
                Password  = registerUser.Password,
                Salt      = registerUser.Salt,
                Role      = registerUser.Role,
                LastName  = registerUser.LastName,
                CreatedOn = DateTime.UtcNow
            };

            _travelContext.Add(entity);
            var status = _travelContext.SaveChanges();

            return(status);
        }
Exemple #6
0
        public async Task <IActionResult> Create([Bind("TourName,Date")] Tours tours)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(tours);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(View(tours));
        }
Exemple #7
0
 public Trip Add(Trip trip)
 {
     return(_context.Add(trip).Entity);
 }