Esempio n. 1
0
        public IActionResult gerateCopyTheSurvey(decimal id_survey)
        {
            var surveyCopy = (from survey in _csxContext.Surveys
                              where survey.id_survey.Equals(id_survey) && survey.deletedat == null
                              select new Surveys
            {
                title = "Clone - " + survey.title,
                description = survey.description,
                language = survey.language,
                active = true,
                fk_company = survey.fk_company,
                createdat = DateTime.Now,
                fk_user_create = survey.fk_user_create,
                color_button = survey.color_button,
            }).FirstOrDefault();

            _csxContext.Surveys.Add(surveyCopy);
            _csxContext.SaveChanges();

            //Copy Survey
            var    actionBusiness = new ActionBusiness(_csxContext);
            var    user           = _csxContext.Users.Find(surveyCopy.fk_user_create);
            string type           = "CopySurvey";
            string message        = string.Format("O Usuário [{0}] copiou a pesquisa [{1}].", user.full_name, surveyCopy.title);
            var    action         = actionBusiness.Save(user, type, message, 0, (int)surveyCopy.id_survey);

            return(Ok(surveyCopy.id_survey));
        }
Esempio n. 2
0
        public IActionResult saveAction([FromBody] Actions action)
        {
            try
            {
                var actionBusiness = new ActionBusiness(_csxContext);
                var result         = actionBusiness.Save(action);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(NotFound("Erro ao Salvar: " + ex.Message));
            }
        }
Esempio n. 3
0
        public IActionResult Security([FromBody] Users User)
        {
            try
            {
                if (User.email == null)
                {
                    return(Unauthorized(new { error = "E-mail não encontrado." }));
                }
                if (User.password == null)
                {
                    return(Unauthorized(new { error = "Senha não encontrada." }));
                }

                var password = User.password;

                using (MD5 md5Hash = MD5.Create())
                {
                    password = Token.GetMd5Hash(md5Hash, User.password);
                }

                var user        = _csxContext.Users.Where(x => x.email == User.email && x.password == password).First();
                var tokenString = Token.Factory(user);

                //Action Login
                var    actionBusiness = new ActionBusiness(_csxContext);
                string type           = "Login";
                string message        = string.Format("Usuário {0} efetuou login.", user.full_name);
                var    action         = actionBusiness.Save(user, type, message);

                UpdateLastAccess(user);
                //Limpando a senha
                user.password = "";
                //Result is the token.
                return(Ok(new
                {
                    authenticated = true,
                    accessToken = tokenString
                }));
            }
            catch (Exception ex) {
                return(Unauthorized(new{
                    autenticated = false,
                    error = "E-mail ou senha inválido!",
                    ex = ex
                }));

                throw ex;
            }
        }
Esempio n. 4
0
        public IActionResult deleteSurvey([FromBody] Surveys survey)
        {
            try
            {
                survey.deletedat = DateTime.Now;
                _csxContext.Surveys.Update(survey);
                _csxContext.SaveChanges();

                //Delete Survey
                var    actionBusiness = new ActionBusiness(_csxContext);
                var    user           = _csxContext.Users.Find(survey.fk_user_create);
                string type           = "SurveyDeleted";
                string message        = string.Format("Usuário {0} deletou o survey {1} com o id {2}.", user.full_name, survey.title, survey.id_survey);
                var    action         = actionBusiness.Save(user, type, message);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(NotFound(ex));
            }
        }
Esempio n. 5
0
        public IActionResult updateSurvey([FromBody] Surveys survey)
        {
            try
            {
                survey.updatedat = DateTime.Now;
                //survey.message_whatsapp = Helpers.HtmlToWhatsApp(survey.message_whatsapp);
                _csxContext.Surveys.Update(survey);
                _csxContext.SaveChanges();

                //Update Survey
                var    actionBusiness = new ActionBusiness(_csxContext);
                var    user           = _csxContext.Users.Find(survey.fk_user_create);
                string type           = "UpdateSurvey";
                string message        = string.Format("O Usuário [{0}] atualizou a pesquisa [{1}].", user.full_name, survey.title);
                var    action         = actionBusiness.Save(user, type, message, 0, (int)survey.id_survey);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(NotFound(ex));
            }
        }
Esempio n. 6
0
        public IActionResult saveSurvey([FromBody] Surveys survey)
        {
            try
            {
                survey.active    = true;
                survey.createdat = DateTime.Now;
                _csxContext.Surveys.Add(survey);
                _csxContext.SaveChanges();

                //Save Survey
                var    actionBusiness = new ActionBusiness(_csxContext);
                var    user           = _csxContext.Users.Find(survey.fk_user_create);
                string type           = "SaveSurvey";
                string message        = string.Format("Usuário {0} salvou o survey {1} com o id {2}.", user.full_name, survey.title);
                var    action         = actionBusiness.Save(user, type, message, 0, (int)survey.id_survey);

                return(Ok());
            }
            catch (System.Exception)
            {
                return(NotFound("Erro ao Salvar"));
            }
        }
Esempio n. 7
0
        public IActionResult newSurvey([FromBody] Surveys survey)
        {
            try
            {
                survey.language  = String.IsNullOrEmpty(survey.language) ? "pt_BR" : survey.language;
                survey.createdat = DateTime.Now;
                survey.active    = true;
                _csxContext.Surveys.Add(survey);
                _csxContext.SaveChanges();

                //New Survey
                var    actionBusiness = new ActionBusiness(_csxContext);
                var    user           = _csxContext.Users.Find(survey.fk_user_create);
                string type           = "NewSurvey";
                string message        = string.Format("O Usuário [{0}] criou uma nova pesquisa [{1}].", user.full_name, survey.title);
                var    action         = actionBusiness.Save(user, type, message, 0, (int)survey.id_survey);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(NotFound(ex));
            }
        }