public async Task <ActionResult <SpecialtyDto> > Post([FromBody] SpecialtyDto specialty)
        {
            try
            {
                if (specialty == null)
                {
                    return(BadRequest("Specialty object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                var map = _mapper.Map <Specialty>(specialty);

                var res = await _specialtyBus.AddSpecialty(map);

                var revMap = _mapper.Map <SpecialtyDto>(res);

                return(CreatedAtRoute("GetSpecialtyById", new { id = res.Id }, revMap));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Example #2
0
        public SpecialtyDto UpdateSpecialty(int id, SpecialtyDto specialty)
        {
            if (id <= 0)
            {
                RaiseNotification(nameof(id));
            }

            if (specialty == null)
            {
                RaiseNotification(nameof(specialty));
            }

            if (Notification.HasNotification())
            {
                return(new SpecialtyDto());
            }

            var specialtyBuilder = new SpecialtyBuilder(Notification)
                                   .WithId(id)
                                   .WithDescription(specialty.Description);

            _service.UpdateSpecialty(specialtyBuilder);

            specialty.Id = id;
            return(specialty);
        }
Example #3
0
        public void Should_Update_Specialty_With_Success()
        {
            //Arrange
            var specialtyDto = new SpecialtyDto()
            {
                Id          = 2,
                Description = "Cirurgia Geral"
            };

            //Act
            var result = _specialtyAppService.CreateSpecialty(specialtyDto);

            //Assert
            Assert.False(LocalNotification.HasNotification());

            result.Id.ShouldBe(2);

            result.Description = "Cirurgia Vascular";

            result = _specialtyAppService.UpdateSpecialty(result.Id, result);

            //Assert
            Assert.False(LocalNotification.HasNotification());
            result.Description.ShouldBe("Cirurgia Vascular");
        }
Example #4
0
        public static int AddIfNotExists(SpecialtyDto specialty)
        {
            var specialtyId = GetSpecialtyId(specialty);

            if (specialtyId != -1)
            {
                return(specialtyId);
            }

            int result = -1;

            using (OleDbCommand oleDbCommand = new OleDbCommand())
            {
                // Set the command object properties
                oleDbCommand.Connection  = new OleDbConnection(ConnectionConfig.ConnectionString);
                oleDbCommand.CommandType = CommandType.Text;
                oleDbCommand.CommandText = insertSpecialty;

                // Add the input parameters to the parameter collection
                oleDbCommand.Parameters.AddWithValue("@Name", specialty.Name);
                // Open the connection, execute the query and close the connection
                oleDbCommand.Connection.Open();
                var rowsAffected = oleDbCommand.ExecuteNonQuery();
                result = oleDbCommand.Connection.GetLatestAutonumber();
                oleDbCommand.Connection.Close();

                if (rowsAffected > 0)
                {
                    return(result);
                }

                Logger.LogException("Could not add specialty");
                return(-1);
            }
        }
Example #5
0
        public static int GetSpecialtyId(SpecialtyDto specialty)
        {
            DataTable dataTable = new DataTable();
            DataRow   dataRow;

            using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter())
            {
                // Create the command and set its properties
                dataAdapter.SelectCommand             = new OleDbCommand();
                dataAdapter.SelectCommand.Connection  = new OleDbConnection(ConnectionConfig.ConnectionString);
                dataAdapter.SelectCommand.CommandType = CommandType.Text;
                dataAdapter.SelectCommand.CommandText = getSpecialtyIdByName;

                // Add the parameter to the parameter collection
                dataAdapter.SelectCommand.Parameters.AddWithValue("@Name", specialty.Name);

                // Fill the datatable From adapter
                dataAdapter.Fill(dataTable);

                // Get the datarow from the table
                dataRow = dataTable.Rows.Count > 0 ? dataTable.Rows[0] : null;

                return(dataRow == null ? -1 : int.Parse(dataRow[0].ToString()));
            }
        }
Example #6
0
        public async Task <ActionResult <SpecialtyDto> > CreateSpecialty(SpecialtyDto specialty)
        {
            var specialtyCreate = _mapper.Map <Specialty>(specialty);

            _context.Specialties.Add(specialtyCreate);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSpecialty", new { id = specialty.Id }, specialty));
        }
Example #7
0
        public IActionResult Put(int id, [FromBody] SpecialtyDto specialty)
        {
            var response = _specialtyAppService.UpdateSpecialty(id, specialty);

            return(CreateResponse <SpecialtyDto>()
                   .FromErrorEnum(SpecialtyDto.Error.PutSpecialty)
                   .WithMessage(AppConsts.LocalizationSourceName, SpecialtyDto.Error.PutSpecialty)
                   .WithDto(response)
                   .Build());
        }
Example #8
0
        public async Task <SpecialtyDto> CreateSpecialityAsync(SpecialtyDto specialty)
        {
            var newSpeciality = _mapper.Map <Specialty>(specialty);

            _specialitiesUnitOfWork.Repository.Add(newSpeciality);

            await _specialitiesUnitOfWork.SaveChangesAsync().ConfigureAwait(false);

            return(await GetSpecialityAsync(newSpeciality.Id).ConfigureAwait(false));
        }
 public static SpecialtyViewModel Map(SpecialtyDto dto)
 {
     return(new SpecialtyViewModel
     {
         Id = dto.Id,
         Bonus = dto.Bonus,
         Title = dto.Title,
         EmployeeId = dto.EmployeeId
     });
 }
Example #10
0
        public async Task UpdateSpecialityAsync(SpecialtyDto specialty)
        {
            var specialityToUpdate = await _specialitiesUnitOfWork.Repository.GetByIdAsync(specialty.Id).ConfigureAwait(false);

            if (specialityToUpdate == null)
            {
                throw new ResourceNotFoundException($"Спеціальність {specialty.Id} не знайдена");
            }

            specialityToUpdate.Name = specialty.Name;
            specialityToUpdate.Code = specialty.Code;

            await _specialitiesUnitOfWork.SaveChangesAsync().ConfigureAwait(false);
        }
Example #11
0
        public static Specialty Map(SpecialtyDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new Specialty
            {
                Id = dto.Id,
                Bonus = dto.Bonus,
                Title = dto.Title
            });
        }
Example #12
0
        public void MapTo_SpecialtyDto_To_SpecialtyPoco()
        {
            var dto = new SpecialtyDto
            {
                Id          = 1,
                Description = "Cirurgia Geral"
            };

            var mappPoco = dto.MapTo <SpecialtyPoco>();

            Assert.NotNull(mappPoco);
            Assert.Equal(mappPoco.Id, mappPoco.Id);
            Assert.Equal(mappPoco.Description, mappPoco.Description);
        }
Example #13
0
        public async Task Post_Empty_Specialty_And_Return_Bad_Request()
        {
            //Arrange
            var specialtyDto = new SpecialtyDto();

            // Act
            var response = await PostResponseAsObjectAsync <SpecialtyDto, ErrorResponse>(
                $"/{RouteConsts.Specialty}",
                specialtyDto,
                HttpStatusCode.BadRequest
                );

            // Assert
            response.Message.ShouldBe("PostSpecialty");
            response.DetailedMessage.ShouldBe("PostSpecialty");
            Assert.True(response.Details.Any(a => a.Message == Specialty.Error.SpecialtyDescriptionMustHaveValue.ToString()));
        }
Example #14
0
        public async Task Post_Specialty_With_Success()
        {
            //Arrange
            var specialtyDto = new SpecialtyDto()
            {
                Id          = 3,
                Description = "Cirurgia Torácica"
            };

            // Act
            var response = await PostResponseAsObjectAsync <SpecialtyDto, SpecialtyDto>(
                $"/{RouteConsts.Specialty}",
                specialtyDto
                );

            // Assert
            Assert.Equal(response.Description, "Cirurgia Torácica");
        }
Example #15
0
        public SpecialtyDto CreateSpecialty(SpecialtyDto specialty)
        {
            if (specialty == null)
            {
                RaiseNotification(nameof(specialty));
            }

            if (Notification.HasNotification())
            {
                return(new SpecialtyDto());
            }

            var specialtyBuilder = new SpecialtyBuilder(Notification)
                                   .WithId(specialty.Id)
                                   .WithDescription(specialty.Description);

            specialty.Id = _service.CreateSpecialty(specialtyBuilder);

            return(specialty);
        }
Example #16
0
        private static void SetSpecialtyNameAndYearOfStudying(String columnValue)
        {
            try
            {
                var comaIndex     = columnValue.IndexOf(",");
                var specialtyName = columnValue.Substring(0, comaIndex);

                specialtyName = specialtyName.Replace("\"", "").Trim();

                _specialty = new SpecialtyDto {
                    Name = specialtyName
                };

                _yearOfStudying = Convert.ToInt32(Regex.Match(columnValue.Substring(comaIndex), @"\d+").Value);
            }
            catch (Exception exc)
            {
                Logger.LogException(exc);
            }
        }
Example #17
0
        public async Task Put_Specialty_When_Not_Exists_Return_Not_Found()
        {
            //Arrange
            var specialtyDto = new SpecialtyDto()
            {
                Id          = 10,
                Description = "Cirurgia Torácica"
            };

            // Act
            var response = await PutResponseAsObjectAsync <SpecialtyDto, ErrorResponse>(
                $"{RouteConsts.Specialty}/10",
                specialtyDto,
                HttpStatusCode.NotFound
                );

            // Assert
            response.Message.ShouldBe("PutSpecialty");
            response.DetailedMessage.ShouldBe("PutSpecialty");
            Assert.True(response.Details.Any(a => a.Message == Specialty.Error.CouldNotFindSpecialty.ToString()));
        }
Example #18
0
        public async Task Put_Specialty_With_Success()
        {
            //Arrange
            var specialtyDto = new SpecialtyDto()
            {
                Id          = 1,
                Description = "Cirurgia Torácica"
            };

            // Act
            await PutResponseAsObjectAsync <SpecialtyDto, SpecialtyDto>(
                $"{RouteConsts.Specialty}/1",
                specialtyDto
                );

            var response = await GetResponseAsObjectAsync <SpecialtyDto>(
                $"{RouteConsts.Specialty}/1"
                );

            // Assert
            Assert.Equal(response.Id, 1);
            Assert.Equal(response.Description, "Cirurgia Torácica");
        }
Example #19
0
        public async Task <IActionResult> UpdateSpecialty(int id, SpecialtyDto specialty)
        {
            if (id != specialty.Id)
            {
                return(BadRequest());
            }

            var specialtyUpdated = await _context.Specialties.FindAsync(id);

            if (specialtyUpdated == null)
            {
                return(NotFound());
            }

            specialtyUpdated.Name = specialty.Name;

            _context.Entry(specialtyUpdated).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpecialtyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #20
0
        public async Task Post_Specialty_Should_Be_Insert_And_Update_Item()
        {
            //Arrange
            var specialtyDto = new SpecialtyDto()
            {
                Id          = 3,
                Description = "Cirurgia Torácica"
            };

            // Act
            var response = await PostResponseAsObjectAsync <SpecialtyDto, SpecialtyDto>(
                $"/{RouteConsts.Specialty}",
                specialtyDto
                );

            // Assert
            response.Id.ShouldBe(3);

            var updateParam = new SpecialtyDto()
            {
                Description = "Descrição Alterada Teste"
            };

            // Act
            await PutResponseAsObjectAsync <SpecialtyDto, SpecialtyDto>(
                $"/{RouteConsts.Specialty}/{response.Id}",
                updateParam
                );

            response = await GetResponseAsObjectAsync <SpecialtyDto>(
                $"/{RouteConsts.Specialty}/{response.Id}"
                );

            //Assert
            response.Description.ShouldBe("Descrição Alterada Teste");
        }