public async Task <IActionResult> Create([FromBody] CreateClienteDto resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var cliente = _mapper.Map <CreateClienteDto, Cliente>(resource);
            var usuario = new Usuario()
            {
                Nome           = cliente.Nome,
                Senha          = cliente.Senha,
                CpfMatricula   = cliente.Cpf,
                DataNascimento = cliente.DataNascimento,
                TipoUsuario    = TipoUsuario.Cliente,
                Endereco       = new Endereco()
                {
                    Cep         = resource.Cep,
                    Cidade      = resource.Cidade,
                    Complemento = resource.Complemento,
                    Estado      = resource.Estado,
                    Logradouro  = resource.Logradouro,
                    Numero      = resource.Numero,
                }
            };
            var result = await _usuarioService.CreateAsync(usuario);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(StatusCode(201));
        }
        ///<summary>
        ///Adds a comment with specified parameters
        /// </summary>
        public async Task <Comment> CreateCommentAsync(Comment entity)
        {
            RestConnector.AwaitContinueOnCapturedContext = false;
            var createdEntity = await es.CreateAsync(workspaceContext, entity, commentFields);

            return(createdEntity);
        }
Exemplo n.º 3
0
        public async void GetProductById(string expectedName)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestGetItemDb").Options;

            var id = Guid.NewGuid();

            using (var context = new ApplicationDbContext(options))
            {
                // 1. Arrange
                var product = new Product
                {
                    Id          = id,
                    Name        = "Keyboard",
                    Quantity    = 20,
                    Description = "",
                    Enable      = true
                };

                var _productService = new EntityService <Product>(context);
                await _productService.CreateAsync(product);
            }

            using (var context = new ApplicationDbContext(options))
            {
                var _productService = new EntityService <Product>(context);
                var result          = await _productService.GetByIdAsync(id);

                Assert.NotNull(result);
                Assert.NotEmpty(result.Name);
                Assert.Equal(expectedName, result.Name);
            }
        }
Exemplo n.º 4
0
        public async void AddProduct(string expectedName)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestNewDb").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var product = new Product
                {
                    Id          = Guid.NewGuid(),
                    Name        = "Keyboard",
                    Quantity    = 20,
                    Description = "",
                    Enable      = true
                };

                var _productService = new EntityService <Product>(context);
                await _productService.CreateAsync(product);
            }

            using (var context = new ApplicationDbContext(options))
            {
                var _productService = new EntityService <Product>(context);
                var result          = await _productService.FindByConditionAsync(p => p.Enable);

                Assert.NotEmpty(result);
                Assert.Single(result);
                Assert.NotEmpty(result.First().Name);
                Assert.Equal(expectedName, result.First().Name);
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PostAsync([FromBody] CreateCategoriaDto resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var categoria = _mapper.Map <CreateCategoriaDto, Categoria>(resource);
            var result    = await _categoriaService.CreateAsync(categoria);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(StatusCode(201));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> PostAsync([FromBody] CreateVeiculoDto resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var veiculo = _mapper.Map <CreateVeiculoDto, Veiculo>(resource);
            var result  = await _veiculoService.CreateAsync(veiculo);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(StatusCode(201));
        }
Exemplo n.º 7
0
        static Entity GetLiteralInDB(string name, string value, LiteralGroup?groupName = null)
        {
            if (_db == null)
            {
                _db = new EntityService(Configuration.Config);
            }

            var fieldLists = new List <KeyValuePair <string, object> >();

            fieldLists.Add(new KeyValuePair <string, object>("name", name));

            if (groupName.HasValue)
            {
                fieldLists.Add(new KeyValuePair <string, object>("groupname", groupName.Value.ToString()));
            }

            var literal = _db.RetrieveAsync("literals", fieldLists, new ColumnSet(true)).GetAwaiter().GetResult();

            if (literal == null)
            {
                literal = new Entity("literals", Guid.NewGuid());

                literal.Attributes.Add("name", name);
                literal.Attributes.Add("text", value);

                if (groupName.HasValue)
                {
                    literal.Attributes.Add("groupname", groupName.Value.ToString());
                }

                literal.Attributes.Add("createdon", DateTime.Now);

                _db.CreateAsync(literal).GetAwaiter();
            }

            return(literal);
        }
        public async Task <IActionResult> PostAsync([FromBody] CreateOperadorDto resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var operador = _mapper.Map <CreateOperadorDto, Operador>(resource);
            var usuario  = new Usuario()
            {
                Nome         = operador.Nome,
                Senha        = operador.Senha,
                CpfMatricula = operador.Matricula,
                TipoUsuario  = TipoUsuario.Operador
            };
            var result = await _usuarioService.CreateAsync(usuario);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(StatusCode(201));
        }