예제 #1
0
        public async Task <bool> Update(ContatoPost contatoPost)
        {
            var success = false;

            var existingcontatoPost = Get(contatoPost.Id);

            if (existingcontatoPost != null)
            {
                existingcontatoPost.Nome          = contatoPost.Nome;
                existingcontatoPost.Canal         = contatoPost.Canal;
                existingcontatoPost.Valor         = contatoPost.Valor;
                existingcontatoPost.Obs           = contatoPost.Obs;
                existingcontatoPost.DataAlteracao = contatoPost.DataAlteracao;

                _databaseContext.ContatoPosts.Attach(existingcontatoPost);

                var numberOfItemsUpdated = await _databaseContext.SaveChangesAsync();

                if (numberOfItemsUpdated == 1)
                {
                    success = true;
                }
            }

            return(success);
        }
예제 #2
0
        public static bool IsValid(this ContatoPost contatoPost, out IEnumerable <string> errors)
        {
            var validator = new ContatoPostValidator();

            var validationResult = validator.Validate(contatoPost);

            errors = AggregateErrors(validationResult);

            return(validationResult.IsValid);
        }
예제 #3
0
        public async Task <IActionResult> Update([FromBody] ContatoPost contatoPost)
        {
            if (contatoPost.IsValid(out IEnumerable <string> errors))
            {
                var result = await _contatoPostService.Update(contatoPost);

                return(Ok(result));
            }
            else
            {
                return(BadRequest(errors));
            }
        }
예제 #4
0
        public async Task <bool> Create(ContatoPost contatoPost)
        {
            var success = false;

            _databaseContext.ContatoPosts.Add(contatoPost);

            var numberOfItemsCreated = await _databaseContext.SaveChangesAsync();

            if (numberOfItemsCreated == 1)
            {
                success = true;
            }

            return(success);
        }
예제 #5
0
        public void CreateLote()
        {
            for (int a = 0; a < 50; a++)
            {
                ContatoPost contatoPost = new ContatoPost {
                    Id    = a.ToString(),
                    Nome  = "Nome" + a.ToString(),
                    Canal = "Canal" + a.ToString(),
                    Valor = "valor" + a.ToString(),
                    Obs   = "Obs" + a.ToString()
                };

                _contatoPostService.Create(contatoPost);
            }
        }
예제 #6
0
        public async Task <IActionResult> Create([FromBody] ContatoPost contatoPost)
        {
            if (contatoPost.IsValid(out IEnumerable <string> errors))
            {
                var result = await _contatoPostService.Create(contatoPost);

                return(CreatedAtAction(
                           nameof(GetAllByUserAccountId),
                           new { id = result.Nome }, result));
            }
            else
            {
                return(BadRequest(errors));
            }
        }
예제 #7
0
        public async Task <ContatoPost> Update(ContatoPost contatoPost)
        {
            contatoPost.DataAlteracao = DateTime.UtcNow;

            var success = await _repository.Update(contatoPost);

            if (success)
            {
                return(contatoPost);
            }
            else
            {
                return(null);
            }
        }