Beispiel #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));
        }
        public void Add(ActionBusiness action)
        {
            var entity = ActionMapper.Map(action);

            databaseContext.Action.Add(entity);
            databaseContext.SaveChanges();
        }
Beispiel #3
0
        public async Task <Guid> EditAdvisorAsync(int id, string name, string description, bool changePicture, Stream pictureStream, string pictureExtension)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new BusinessException("Name must be filled.");
            }
            if (name.Length > 50)
            {
                throw new BusinessException("Name cannot have more than 50 characters.");
            }
            if (!string.IsNullOrEmpty(description) && description.Length > 160)
            {
                throw new BusinessException("Description cannot have more than 160 characters.");
            }

            byte[] picture = null;
            if (changePicture && pictureStream != null)
            {
                picture = GetPictureBytes(pictureStream, pictureExtension);
            }

            var advisor = Data.GetAdvisor(id);

            if (advisor == null || !advisor.Enabled)
            {
                throw new NotFoundException("Trader not found");
            }
            if (advisor.Email.ToLower() != LoggedEmail.ToLower())
            {
                throw new UnauthorizedException("Invalid credentials");
            }

            var previousData = $"(Previous) Name: {advisor.Name} - Change Picture: {changePicture} - Url Guid: {advisor.UrlGuid} - Description: {advisor.Description}";

            if (changePicture)
            {
                var previousGuid = advisor.UrlGuid;
                advisor.UrlGuid = Guid.NewGuid();
                if (await AzureStorageBusiness.UploadUserPictureFromBytesAsync($"{advisor.UrlGuid}.png", picture ?? GetNoUploadedImageForAdvisor(advisor)))
                {
                    await AzureStorageBusiness.DeleteUserPicture($"{previousGuid}.png");
                }
            }
            advisor.Name        = name;
            advisor.Description = description;
            Update(advisor);

            ActionBusiness.InsertEditAdvisor(advisor.Id, previousData);
            var cachedAdvisor = AdvisorRankingBusiness.ListAdvisorsFullData().FirstOrDefault(c => c.Id == advisor.Id);

            if (cachedAdvisor != null)
            {
                cachedAdvisor.Name        = advisor.Name;
                cachedAdvisor.Description = advisor.Description;
                cachedAdvisor.UrlGuid     = advisor.UrlGuid;
            }

            return(advisor.UrlGuid);
        }
        public void Update(ActionBusiness action)
        {
            var entity = databaseContext.Action.Find(action.Id);

            if (entity != null)
            {
                entity = ActionMapper.Map(action);
                databaseContext.SaveChanges();
            }
        }
Beispiel #5
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));
            }
        }
Beispiel #6
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;
            }
        }
Beispiel #7
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));
            }
        }
Beispiel #8
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));
            }
        }
Beispiel #9
0
        public async Task <IActionResult> updateActive(decimal id_survey)
        {
            try
            {
                var survey = _csxContext.Surveys.Find(id_survey);
                survey.active = !survey.active;
                _csxContext.Surveys.Update(survey);
                await _csxContext.SaveChangesAsync();

                //Status Survey
                var    actionBusiness = new ActionBusiness(_csxContext);
                var    user           = _csxContext.Users.Find(survey.fk_user_create);
                string type           = survey.active ? "SurveyActived" : "SurveyDisabled";
                string message        = string.Format("Usuário {0} atualizou o status do survey {1} com o id {2}.", user.full_name, survey.title, survey.id_survey);
                await actionBusiness.SaveAsync(survey.fk_user_create, survey.fk_company, type, message);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(NotFound(ex));
            }
        }
Beispiel #10
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"));
            }
        }
Beispiel #11
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));
            }
        }
 protected virtual IActionResult GetDashboard()
 {
     return(Ok(ActionBusiness.GetDashboardData()));
 }
 /// <summary>
 /// Constructeur principal
 /// </summary>
 public ActionService()
 {
     _Business = new ActionBusiness();
 }