Exemplo n.º 1
0
        public IActionResult GetColumns(int accountId, int formId)
        {
            try
            {
                _logger.Log(LogLevel.Information, "columns");
                _logger.Log(LogLevel.Critical, "columns test");
                if (!_accountRepository.AccountExists(accountId))
                {
                    _logger.LogInformation($"Account with id {accountId} wasn't found when accessing columns.");
                    return(NotFound());
                }

                if (!_formRepository.FormExists(formId))
                {
                    _logger.LogInformation($"Form with id {formId} wasn't found when accessing forms.");
                    return(NotFound());
                }

                var columnsForForm        = _formRepository.GetColumnForForm(formId);
                var columnsForFormResults =
                    Mapper.Map <IEnumerable <ColumnDto> >(columnsForForm);

                return(Ok(columnsForFormResults));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"Exception while getting column for form with id {formId}.", ex);
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
Exemplo n.º 2
0
        public IActionResult GetAccount(int id, bool includeSubAccounts = false)
        {
            if (!_accountRepo.AccountExists(id))
            {
                return(NotFound());
            }

            var account = _accountRepo.GetAccount(id, includeSubAccounts);

            if (!includeSubAccounts)
            {
                var resultsWithout = new AccountWithoutSubAccountsDto()
                {
                    Id          = account.Id,
                    Name        = account.Name,
                    Description = account.Description
                };
                return(Ok(resultsWithout));
            }

            var resultWith = new AccountWithSubAccountsDto()
            {
                Id          = account.Id,
                Name        = account.Name,
                Description = account.Description,
                SubAccounts = _mapSubAccountsToDto(account.SubAccounts.ToList())
            };

            return(Ok(resultWith));
        }
Exemplo n.º 3
0
        public JsonResult GetInformationAccount(int id)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(id))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //This is get all information of account
                AccountEntity account = _accountRepository.GetAccountById(id);

                return(Json(account));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "AccountId,Name,Password,PhoneNumber,ContactListId")] Account account)
        {
            if (ModelState.IsValid)
            {
                if (account.PhoneNumber.All(char.IsDigit))
                {
                    if (!accRep.AccountExists(account))
                    {
                        account.Password = Argon2.Hash(account.Password);
                        accRep.CreateAcccount(account);
                        return(RedirectToAction("LogIn", "Accounts"));
                    }
                    else
                    {
                        ModelState.AddModelError("reg-error", "Account already exists");
                        return(RedirectToAction("Create"));
                    }
                }
                else
                {
                    ModelState.AddModelError("phone-error", "PhoneNumber must only contain digits.");
                    return(RedirectToAction("Create"));
                }
            }

            return(View(account));
        }
Exemplo n.º 5
0
        public IActionResult CreateAction(int accountId, int formId,
                                          [FromBody] FormActionsDto formAction)
        {
            if (formAction == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_accountRepository.AccountExists(accountId))
            {
                return(NotFound());
            }

            if (!_formRepository.FormExists(formId))
            {
                return(NotFound());
            }

            var columnEntity = _formRepository.GetDistinctColumnForForm(formId);

            if (columnEntity == null)
            {
                return(NotFound());
            }
            else
            {
                try
                {
                    var            clientTablePrefix      = Startup.Configuration["AppSettings:clientTablePrefix"];
                    var            clientConnectionString = Startup.Configuration["ConnectionStrings:connFDClientData"];
                    ClientDBHelper clientDBHelper         = new ClientDBHelper(accountId, formId, clientConnectionString, clientTablePrefix);

                    if (clientDBHelper.TableExists(clientDBHelper.GetClientTableName()))
                    {
                        clientDBHelper.UpdateTable(columnEntity);
                    }
                    else
                    {
                        clientDBHelper.CreateTable(columnEntity);
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }

            return(Ok());
        }
Exemplo n.º 6
0
 public bool DeleteAccount(int id)
 {
     if (!_accountRepository.AccountExists(id))
     {
         // Transaction not found to delete.
         return(false);
     }
     else
     {
         // Delete the transaction from records.
         return(_accountRepository.DeleteAccount(id));
     }
 }
        public async Task <IActionResult> ValidateAccount([FromBody] SaveUserResource user)
        {
            if (await repository.AccountExists(user))
            {
                return(Ok(user));
            }
            else
            {
                repository.AddAccount(user);
                await unitOfWork.CompleteAsync();

                return(Ok(user));
            }
        }
        public ActionResult <IEnumerable <AccountHistoryDto> > GetAccountHistories(Guid account_id)
        {
            if (!_accountRepository.AccountExists(account_id))
            {
                throw new NotFoundException("No account with this id");
            }

            var accountHistoryFromRepo = _accountRepository.GetAccountHistories(account_id);
            var result = _mapper.Map <IEnumerable <AccountHistoryDto> >(accountHistoryFromRepo);

            return(Ok(new { status = "ok", result }));
        }
Exemplo n.º 9
0
        public JsonResult GetInformationAccount(int accountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //Get list all history by id account
                List <HistoryEntity> list = _historyRepository.getHistoryByAccount(accountId);

                List <HistoryResult> listResult = new List <HistoryResult>();

                foreach (var history in list)
                {
                    HistoryResult result = new HistoryResult();
                    ExamEntity    exam   = _examRepository.GetExamById(history.ExamId);
                    GroupEntity   group  = _groupRepository.GetGroupById(history.GroupId);
                    result.nameExam  = exam.Name;
                    result.nameGroup = group.Name;

                    listResult.Add(result);
                }

                return(Json(listResult));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
Exemplo n.º 10
0
        public ResultGeneric <PostClientAccountResponse> Register(PostClientAccountRequest entity)
        {
            var accountCreate = new ResultGeneric <PostClientAccountResponse>();

            var newClient  = ClientConverter.Parse(entity);
            var newAccount = AccountConverter.Parse(entity);
            var clientID   = new Guid();

            #region Client
            var client = clientRepository.getByDocument(entity.CPF);
            if (client != null)
            {
                clientID = client.ClientID;
            }
            else
            {
                clientRepository.Insert(newClient);
                clientID = newClient.ClientID;
            }
            #endregion

            #region Account

            if (!accountRepository.AccountExists(entity.AgencyNumber, entity.AccountNumber))
            {
                newAccount.ClientID = clientID;
                accountRepository.Insert(newAccount);

                accountCreate.Success = true;
            }
            else
            {
                accountCreate.Success = false;
                accountCreate.Errors.Add("Conta já existente");
            }

            accountCreate.Data = ClientConverter.Parse(newClient, newAccount);
            #endregion

            return(accountCreate);
        }
Exemplo n.º 11
0
        public JsonResult DeleteMember(int groupId, int accountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id group exist in the database
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //This is get all member of group by id acount
                var memberEntity = _groupMemberRepository.GetGroupMemberByGroupIdAndAccountId(groupId, accountId);

                if (memberEntity == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationMember));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_MEMBER)));
                }

                //This is query to delete member
                _groupRepository.DeleteMember(memberEntity);

                if (!_groupRepository.Save())
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest));
                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }

                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.memberDeleted));
                return(Json(MessageResult.GetMessage(MessageType.MEMBER_DELETED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
Exemplo n.º 12
0
        public IActionResult Register(AccountForRegisterDto model)
        {
            // hash the password
            if (!ModelState.IsValid)
            {
                return(BadRequest("An error has occurred."));
            }
            model.Email = model.Email.ToLower();
            if (_accountRepository.AccountExists(model.Email))
            {
                return(BadRequest("Account already exists."));
            }
            var accountToCreate = new Account
            {
                Email       = model.Email,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                DateCreated = DateTime.Now
            };
            var createdAccount = _accountRepository.Register(accountToCreate, model.Password);

            return(StatusCode(201));
        }
Exemplo n.º 13
0
        public IActionResult GetForms(int accountId)
        {
            try
            {
                if (!_accountRepository.AccountExists(accountId))
                {
                    _logger.LogInformation($"Account with id {accountId} wasn't found when accessing forms.");
                    return(NotFound());
                }

                var formsForAccount        = _accountRepository.GetFormForAccount(accountId);
                var formsForAccountResults =
                    Mapper.Map <IEnumerable <FormDto> >(formsForAccount);

                return(Ok(formsForAccountResults));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"Exception while getting form for account with id {accountId}.", ex);
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
Exemplo n.º 14
0
 private bool AccountExists(int id)
 {
     return(_repo.AccountExists(id));
 }
Exemplo n.º 15
0
        public JsonResult GetListQuestion(int accountId, int examId, int page)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //Check id exam exist in the database
                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //This is get all questions of the exam by id exam
                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);
                List <AnswerUserEntity>   answerUsers        = _answerUserRepository.GetAnswerUserEntities(accountId);

                List <QuestionEntity> listQuestionEntities = new List <QuestionEntity>();
                foreach (var examQuestion in examQuestionEntity)
                {
                    // Get all informations of the question by questionId and save it in the list
                    QuestionEntity questionEntity = _questionRepository.getQuestionInformation(examQuestion.QuestionId);
                    listQuestionEntities.Add(questionEntity);
                }

                List <QuestionListResult> questionLists = new List <QuestionListResult>();
                foreach (var item in listQuestionEntities)
                {
                    QuestionListResult q = new QuestionListResult();
                    q.questionId    = item.QuestionId;
                    q.part          = item.Part;
                    q.image         = item.Image;
                    q.fileMp3       = item.FileMp3;
                    q.questionName  = item.QuestionName;
                    q.A             = item.A;
                    q.B             = item.B;
                    q.C             = item.C;
                    q.D             = item.D;
                    q.correctAnswer = item.CorrectAnswer;
                    q.team          = item.Team;
                    foreach (var answer in answerUsers)
                    {
                        if (q.questionId == answer.QuestionId)
                        {
                            q.answerUser = answer.AnswerKey;
                        }
                    }
                    questionLists.Add(q);
                }

                List <QuestionListResult> pagging = Pagging.GetQuestions(page, questionLists);

                return(Json(pagging));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
Exemplo n.º 16
0
        public IActionResult DeleteAccount(int id, [FromQuery] string action, [FromQuery] string clientaction)
        {
            if (action == "perm")
            {
                if (!_accountRepository.AccountExists(id))
                {
                    return(NotFound());
                }

                var accountEntity = _accountRepository.GetAccount(id, true);
                if (accountEntity == null)
                {
                    return(NotFound());
                }

                var formEntity = _accountRepository.GetFormForAccount(id);
                if (formEntity != null)
                {
                    int formId;
                    foreach (Entities.Form form in formEntity)
                    {
                        formId = form.Id;
                        var columnEntity = _formRepository.GetColumnForForm(formId);
                        if (columnEntity != null)
                        {
                            foreach (Entities.Column column in columnEntity)
                            {
                                _formRepository.DeleteColumn(column);
                            }
                        }

                        _accountRepository.DeleteForm(form);

                        if (clientaction != null && clientaction == "cleanall")
                        {
                            var            clientTablePrefix      = Startup.Configuration["AppSettings:clientTablePrefix"];
                            var            clientConnectionString = Startup.Configuration["ConnectionStrings:connFDClientData"];
                            ClientDBHelper clientDBHelper         = new ClientDBHelper(id, formId, clientConnectionString, clientTablePrefix);

                            clientDBHelper.DropClientTable();
                        }
                    }
                }

                //Delete Acccount
                _accountRepository.DeleteAccount(accountEntity);

                if (!_accountRepository.Save())
                {
                    return(StatusCode(500, "A problem happened while handling your request."));
                }

                //_mailService.Send("Form deleted.",
                //        $"Form {formEntity.Title} with id {formEntity.Id} was deleted.");

                return(NoContent());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 17
0
        public JsonResult GetAnswerKeyAndCorrectAnswer(int examId, int accountId, int anotherAccountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.EXAM_NOT_FOUND)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);

                List <QuestionEntity> listQuestionEntities = new List <QuestionEntity>();
                foreach (var examQuestion in examQuestionEntity)
                {
                    // Get all informations of the question by questionId and save it in the list
                    QuestionEntity questionEntity = _questionRepository.getQuestionInformation(examQuestion.QuestionId);
                    listQuestionEntities.Add(questionEntity);
                }

                List <AnswerUserEntity> answerUserEntities = _answerUserRepository.GetAnswerUserEntities(accountId);

                List <AnswerUserResult> answerUserResults = new List <AnswerUserResult>();

                if (anotherAccountId <= 0)
                {
                    foreach (var examQuestion in listQuestionEntities)
                    {
                        foreach (var item in answerUserEntities)
                        {
                            if (item.QuestionId == examQuestion.QuestionId)
                            {
                                AnswerUserResult answerUser = new AnswerUserResult();
                                answerUser.part          = examQuestion.Part;
                                answerUser.quetionNumber = examQuestion.QuestionNumber;
                                answerUser.answerUser    = item.AnswerKey.ToUpper();
                                answerUser.finalAnswer   = examQuestion.CorrectAnswer.ToUpper();

                                answerUserResults.Add(answerUser);
                            }
                        }
                    }
                }
                else if (anotherAccountId > 0)
                {
                    List <AnswerUserEntity> anotherAccount = _answerUserRepository.GetAnswerUserEntities(anotherAccountId);
                    AccountEntity           nameAnother    = _accountRepository.GetAccountById(anotherAccountId);
                    foreach (var examQuestion in listQuestionEntities)
                    {
                        foreach (var item in answerUserEntities)
                        {
                            foreach (var another in anotherAccount)
                            {
                                if (item.QuestionId == examQuestion.QuestionId && another.QuestionId == examQuestion.QuestionId)
                                {
                                    AnswerUserResult answerUser = new AnswerUserResult();
                                    answerUser.part          = examQuestion.Part;
                                    answerUser.nameAnother   = nameAnother.FullName;
                                    answerUser.quetionNumber = examQuestion.QuestionNumber;
                                    answerUser.answerUser    = item.AnswerKey.ToUpper();
                                    answerUser.finalAnswer   = examQuestion.CorrectAnswer.ToUpper();
                                    answerUser.answerAnother = another.AnswerKey.ToUpper();

                                    if (!item.AnswerKey.Equals(another.AnswerKey))
                                    {
                                        answerUser.status = "uncorrect";
                                    }

                                    answerUserResults.Add(answerUser);
                                }
                            }
                        }
                    }
                }

                return(Json(answerUserResults.OrderBy(a => a.quetionNumber)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
Exemplo n.º 18
0
        private bool AccountExists(int id)
        {
            var accountExistsTask = _repository.AccountExists(id);

            return(accountExistsTask.Result);
        }
Exemplo n.º 19
0
        public bool CheckAccount(string acc)          //check userid exists
        {
            bool account = accountRepository.AccountExists(acc);

            return(account);
        }