Example #1
0
        public async Task <IActionResult> Create([FromBody] CreateProviderReq req)
        {
            var provider = req.toEntity(HttpContext.UserId().Value);
            await providerRepo.Create(provider);

            return(Created($"/api/providers/${provider.Id}", provider));
        }
Example #2
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string id = "0";
                if (!IdTxt.Text.Equals(""))
                {
                    id = IdTxt.Text.ToString();
                }

                provider.Id             = int.Parse(id);
                provider.Identification = IdentificationTxt.Text;
                provider.Name           = NameTxt.Text;
                provider.PublicName     = PublicNameTxt.Text;
                provider.Status         = StatusCbx.SelectedIndex.ToString();

                Provider item = new Provider
                {
                    Id             = provider.Id,
                    Identification = provider.Identification,
                    Name           = provider.Name,
                    PublicName     = provider.PublicName,
                    StatusId       = _Context.Statuses
                                     .Where(x => x.Id == (StatusCbx.SelectedIndex + 1))
                                     .Select(x => x.Id)
                                     .FirstOrDefault()
                };

                if (mode.Equals("Create"))
                {
                    providerRepo.Create(item);
                }
                else
                {
                    providerRepo.Update(item);
                }

                Close();

                MessageBox.Show(
                    text: "Registro guardado con exito",
                    caption: "Informacion",
                    buttons: MessageBoxButtons.OK,
                    icon: MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(
                    text: "Error al guardar los datos",
                    caption: "Error",
                    buttons: MessageBoxButtons.OK,
                    icon: MessageBoxIcon.Error);
            }
        }
Example #3
0
        public void Create_Success_ReturnEntity()
        {
            // Arrange
            var repository = new ProviderRepository();
            var input      = GenerateInput();

            // Act
            var result = repository.Create(input);

            // Assert
            Assert.That(CompareProperties(input, result));
        }
Example #4
0
        public void Get_Success_ReturnEntity()
        {
            // Arrange
            var repository = new ProviderRepository();
            var input      = repository.Create(GenerateInput());

            // Act
            var result = repository.Get(input.Id);

            // Assert
            Assert.IsInstanceOf <Provider>(result);
        }
Example #5
0
        public void Delete_Success_ReturnNull()
        {
            // Arrange
            var repository = new ProviderRepository();
            var input      = repository.Create(GenerateInput());

            // Act
            repository.Delete(input.Id);
            var result = repository.Get(input.Id);

            // Assert
            Assert.IsNull(result);
        }
Example #6
0
        public void Update_Success_ReturnTrue()
        {
            // Arrange
            var repository = new ProviderRepository();
            var input      = repository.Create(GenerateInput());

            var inputForUpdate = GenerateInput(id: input.Id);

            // Act
            var result = repository.Update(inputForUpdate);

            // Assert
            Assert.IsTrue(result);
        }
Example #7
0
        public Provider AddProvider(ProviderForCreationDto provider)
        {
            var newProvider = Mapper.Map <Provider>(provider);

            return(_providerRepository.Create(newProvider));
        }