Пример #1
0
        public async Task <IActionResult> PutLog(long id, Log log)
        {
            if (id != log.LogId)
            {
                return(BadRequest());
            }

            _context.Entry(log).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <User> UpdateTheme(string userId, User user)
        {
            User userToUpdate = _context.Users.Where(u => u.UserId == Convert.ToInt32(userId)).FirstOrDefault();

            userToUpdate.DarkTheme = user.DarkTheme; //== "True" ? 1 : 0;

            await _context.SaveChangesAsync();

            return(await Task.FromResult(user));
        }
Пример #3
0
        public async Task <User> UpdateProfile(int userId, [FromBody] User user)
        {
            User userToUpdate = await _context.Users.Where(u => u.UserId == userId).FirstOrDefaultAsync();

            userToUpdate.FirstName    = user.FirstName;
            userToUpdate.LastName     = user.LastName;
            userToUpdate.EmailAddress = user.EmailAddress;
            userToUpdate.AboutMe      = user.AboutMe;

            await _context.SaveChangesAsync();

            return(await Task.FromResult(user));
        }
Пример #4
0
        public async Task <ActionResult> RegisterUser(User user)
        {
            //in this method you should only create a user record and not authenticate the user
            var emailAddressExists = _context.Users.Where(u => u.EmailAddress == user.EmailAddress).FirstOrDefault();

            if (emailAddressExists == null)
            {
                user.Password = Utility.Encrypt(user.Password);
                user.Source   = "APPL";
                _context.Users.Add(user);
                await _context.SaveChangesAsync();
            }
            return(Ok());
        }
Пример #5
0
        public async Task <User> Get()
        {
            User user         = new User();
            User returnedUser = new User();

            if (User.Identity.IsAuthenticated)
            {
                var emailAddress = User.FindFirstValue(ClaimTypes.Email);
                returnedUser = _context.User.Where(u => u.EmailAddress == emailAddress)
                               .ToList()
                               .FirstOrDefault();

                //case 1: Application User logging in
                //case 2: Application User Registering
                //case 3: External User Logging in
                if (returnedUser != null && (returnedUser.Source == "APPL" || returnedUser.Source == "EXTL"))
                {
                    return(returnedUser);
                }
                //case 4: External User Registering
                else
                {
                    user.EmailAddress  = User.FindFirstValue(ClaimTypes.Email);
                    user.Password      = user.EmailAddress;
                    user.Source        = "EXTL";
                    user.Notifications = 0;
                    user.DarkTheme     = 0;

                    if (_context.User.Count() > 0)
                    {
                        user.UserId = _context.User.Max(u => u.UserId) + 1;
                    }
                    else
                    {
                        user.UserId = 1;
                    }

                    _context.User.Add(user);

                    await _context.SaveChangesAsync();

                    return(user);
                }
            }
            //case 5: User is not logged in
            else
            {
                return(returnedUser);
            }
        }
Пример #6
0
        public async Task <ActionResult <User> > GetCurrentUser()
        {
            User currentUser = new User();

            if (User.Identity.IsAuthenticated)
            {
                currentUser.EmailAddress = User.FindFirstValue(ClaimTypes.Email);
                currentUser = await _context.Users.Where(u => u.EmailAddress == currentUser.EmailAddress).FirstOrDefaultAsync();

                if (currentUser == null)
                {
                    currentUser              = new User();
                    currentUser.UserId       = _context.Users.Max(user => user.UserId) + 1;
                    currentUser.EmailAddress = User.FindFirstValue(ClaimTypes.Email);
                    currentUser.Password     = Utility.Encrypt(currentUser.EmailAddress);
                    currentUser.Source       = "EXTL";

                    _context.Users.Add(currentUser);
                    await _context.SaveChangesAsync();
                }
            }
            return(await Task.FromResult(currentUser));
        }