Ejemplo n.º 1
0
        public string ResetPassword(string token, string password)
        {
            var user = _context.Users.FirstOrDefault(x => x.Token == token);

            user.Password = Security.HashSensitiveData(password);
            _context.Update(user);
            _context.SaveChanges();
            return("changed");
        }
        public async Task <IActionResult> Edit(int id, [Bind("PersonId,FirstName,MiddleName,LastName,Description,Telephone,AddressId")] Person person)
        {
            if (id != person.PersonId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.PersonId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"] = new SelectList(_context.Addresses, "AddressId", "HouseNumber", person.AddressId);
            return(View(person));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> UpdateAsync([FromBody] QuestionDto questionDto)
        {
            var questionDbo = await ModelsContext.Questions
                              .Include(q => q.Test)
                              .FirstOrDefaultAsync(q => q.Id == questionDto.Id && q.State != EntityState.Deleted);

            if (questionDbo == null)
            {
                return(BadRequest("Question does not exist"));
            }

            var user = await GetUser();

            if (questionDbo.Test.Owner?.Id != user.Id)
            {
                return(Forbid());
            }

            questionDbo.Question = questionDto.Question;
            questionDbo.Answer   = questionDto.Answer;
            ModelsContext.Update(questionDbo);
            await ModelsContext.SaveChangesAsync();

            return(Ok());
        }
        public async Task <ActionResult> LoginAsync([FromBody] UserDto userDto)
        {
            var userDbo = ModelsContext.Users.FirstOrDefault(u => u.Login == userDto.Login && u.Password == userDto.Password);

            if (userDbo == null)
            {
                return(Forbid());
            }

            userDbo.Token     = Guid.NewGuid();
            userDbo.LastLogIn = DateTime.Now;
            ModelsContext.Update(userDbo);
            await ModelsContext.SaveChangesAsync();

            Response.Cookies.Append(AuthConstants.TokenCookie, userDbo.Token.ToString());
            return(Ok(userDbo.Token));
        }
        public async Task <ActionResult> RemoveAsync(Guid testId)
        {
            var user = await GetUser();

            var test = await ModelsContext.Tests.FirstOrDefaultAsync(t => t.Id == testId && t.State != EntityState.Deleted);

            if (test == null)
            {
                return(BadRequest("Test does not exist"));
            }

            if (test.Owner?.Id != user.Id)
            {
                return(Forbid());
            }

            test.State = EntityState.Deleted;
            ModelsContext.Update(test);
            await ModelsContext.SaveChangesAsync();

            return(Ok());
        }
        public async Task <ActionResult> UpdateAsync([FromBody] TestDto testDto)
        {
            var user = await GetUser();

            var test = await ModelsContext.Tests
                       .FirstOrDefaultAsync(t => t.Id == testDto.Id && t.State != EntityState.Deleted);

            if (test == null)
            {
                return(BadRequest("Test not exists"));
            }

            if (test.Owner?.Id != user.Id)
            {
                return(Forbid());
            }

            test.Name = testDto.Name;
            ModelsContext.Update(test);
            await ModelsContext.SaveChangesAsync();

            return(Ok());
        }