public async Task <StandardResponse> DeleteAnswer(ClaimsPrincipal identity, DeleteAnswerViewModel model, ModelStateDictionary modelState)
        {
            if (!modelState.IsValid)
            {
                return(modelState.StandardError());
            }

            using (var t = new ServiceDb().WithTransaction())
            {
                using (var user = await _userService.Become(t.Db, identity, null))
                {
                    await _purgeService.PurgeExistingAnswer(t.Db, user, model.Id, new BackupConfig());

                    return(StandardResponse.ForSuccess());
                }
            }
        }
Exemplo n.º 2
0
        public async Task <StandardResponse> Login(HttpContext httpContext, LoginViewModel model, ModelStateDictionary modelState)
        {
            if (!modelState.IsValid)
            {
                return(modelState.StandardError());
            }

            var authContext = new ServiceIdentityList.ServiceAuthContext();
            var isValid     = await TryAuthorize(model.Username, model.Password, httpContext, authContext);

            if (!isValid)
            {
                throw new Exception($"Invalid login attempt for {model.Username}");
            }

            await _auth.SignInAsync(httpContext, model.Username, authContext.ClaimsForUser);

            return(StandardResponse.ForSuccess());
        }
Exemplo n.º 3
0
        public async Task <StandardResponse> DeleteTopic(ClaimsPrincipal identity, TopicDeleteViewModel model, ModelStateDictionary modelState)
        {
            if (!modelState.IsValid)
            {
                return(modelState.StandardError());
            }

            using (var db = new ServiceDb())
            {
                using (var user = await _userService.Become(db, identity))
                {
                    await _topicService.DeleteTopic(db, user, model.TopicId, model.RowVersion);

                    await db.SaveChangesAsync();

                    return(StandardResponse.ForSuccess());
                }
            }
        }
        public async Task <StandardResponse> UpdateAnswer(ClaimsPrincipal identity, UpdateAnswerViewModel model, ModelStateDictionary modelState)
        {
            if (!modelState.IsValid)
            {
                return(modelState.StandardError());
            }

            using (var db = new ServiceDb())
            {
                using (var user = await _userService.Become(db, identity, null))
                {
                    await _answerService.UpdateExistingAnswer(db, user, new UpdateAnswer()
                    {
                        AnswerId   = model.AnswerId,
                        NewBody    = model.Body,
                        RowVersion = model.RowVersion
                    });

                    await db.SaveChangesAsync();

                    return(StandardResponse.ForSuccess());
                }
            }
        }