public EmployeeContactDto Create(int employeeID, CreateEmployeeContactDto dto)
        {
            _dbContext.ValidateData(dto, employeeID);
            var entity = dto.ToEntity();

            entity.EmployeeID = employeeID;
            _dbContext.EmployeeContact.Add(entity);

            _dbContext.SaveChanges();

            return(entity.ToDto());
        }
        public IActionResult Create([FromRoute] int employeeID, [FromBody] CreateEmployeeContactDto dto)
        {
            try
            {
                var result = _repo.Create(employeeID, dto);

                return(StatusCode((int)HttpStatusCode.Created, result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
        }
示例#3
0
        public static void ValidateData(this IHDSContext context, CreateEmployeeContactDto dto, int id)
        {
            var errors = new StringBuilder();

            // EmployeeID
            errors.AddIfExists(context.KeyExists <Employee>(id, ValidationMessages.EmployeeIDNotFound));
            // ContactMethodTypeID
            errors.AddIfExists(dto.ContactMethodTypeID.ValidateRequired(ValidationMessages.ContactMethodTypeIDRequired));
            errors.AddIfExists(context.KeyExists <ContactMethodType>(dto.ContactMethodTypeID, ValidationMessages.ContactMethodTypeIDNotFound));
            // ContactMethod Value
            errors.AddIfExists(dto.ContactMethodValue.ValidateRequired(ValidationMessages.ContactMethodValueRequired));
            errors.AddIfExists(dto.ContactMethodValue.ValidateLength(100, ValidationMessages.ContactMethodValueLength));

            if (errors.Length > 0)
            {
                throw new ValidationException(errors.ToString());
            }
        }
示例#4
0
 public static EmployeeContact ToEntity(this CreateEmployeeContactDto dto)
 {
     Init();
     return(Mapper.Map <EmployeeContact>(dto));
 }