public CustomerContactDto Create(int customerID, CreateCustomerContactDto dto)
        {
            _dbContext.ValidateData(dto, customerID);
            var entity = dto.ToEntity();

            entity.CustomerID = customerID;
            _dbContext.CustomerContact.Add(entity);

            _dbContext.SaveChanges();

            return(entity.ToDto());
        }
        public IActionResult Create([FromRoute] int customerID, [FromBody] CreateCustomerContactDto dto)
        {
            try
            {
                var result = _repo.Create(customerID, 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, CreateCustomerContactDto dto, int id)
        {
            var errors = new StringBuilder();

            // CustomerID
            errors.AddIfExists(context.KeyExists <Customer>(id, ValidationMessages.CustomerIDNotFound));
            // 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 CustomerContact ToEntity(this CreateCustomerContactDto dto)
 {
     Init();
     return(Mapper.Map <CustomerContact>(dto));
 }