示例#1
0
 public static void ValidateSpecTypeIsSet(ServiceAttributeSpecification spec)
 {
     if (string.IsNullOrWhiteSpace(spec.AttributeType))
     {
         throw new UnprocessableEntityException($"'{nameof(ServiceAttributeSpecification.AttributeType)}' must be set", Guid.Parse(AttributeSpecificationErrorCodes.SPEC_TYPE_MUST_BE_SET));
     }
 }
        public async Task <ServiceAttributeSpecification> CreateAttributeSpecificationAsync(ServiceAttributeSpecification spec)
        {
            var dbSpec = new ServiceAttributeSpecification
            {
                AttributeType = spec.AttributeType,
                Description   = spec.Description,
                Name          = spec.Name,
                ServiceTypeId = spec.ServiceTypeId
            };

            _dataContext.ServiceAttributeSpecifications.Add(dbSpec);
            await _dataContext.SaveChangesAsync();

            return(dbSpec);
        }
示例#3
0
        protected async Task <ServiceAttributeSpecification> CreateAttributeSpecificationAsync(int serviceTypeId)
        {
            var spec = new ServiceAttributeSpecification
            {
                AttributeType = Guid.NewGuid().ToString(),
                Name          = Guid.NewGuid().ToString(),
                Description   = Guid.NewGuid().ToString(),
                ServiceTypeId = serviceTypeId
            };

            using (var ctx = CreateDataContext())
            {
                ctx.ServiceAttributeSpecifications.Add(spec);
                await ctx.SaveChangesAsync();
            }

            return(spec);
        }
示例#4
0
        public Task <ServiceAttributeSpecification> UpdateAttributeSpecificationAsync(ServiceAttributeSpecification spec)
        {
            _serviceTypeValidator.ValidateTypeExists(spec.ServiceTypeId);
            _attributeSpecificationValidator.ValidateSpecificationExists(spec.Id, spec.ServiceTypeId);
            _serviceTypeValidator.CanUpdateServiceType();

            AttributeSpecificationValidator.ValidateNameIsSet(spec);
            AttributeSpecificationValidator.ValidateSpecTypeIsSet(spec);

            return(null);
        }
示例#5
0
 public virtual Task <ServiceAttributeSpecification> UpdateServiceAttributeSpecification(int typeId, int specId, [FromBody] ServiceAttributeSpecification spec)
 {
     spec.ServiceTypeId = typeId;
     spec.Id            = specId;
     return(_attributeSpecificationService.UpdateAttributeSpecificationAsync(spec));
 }
示例#6
0
 public virtual Task <ServiceAttributeSpecification> CreateServiceAttributeSpecification(int typeId, [FromBody] ServiceAttributeSpecification spec)
 {
     HttpContext.Response.StatusCode = (int)HttpStatusCode.Created;
     spec.ServiceTypeId = typeId;
     return(_attributeSpecificationService.CreateAttributeSpecificationAsync(spec));
 }
        public async Task <ServiceAttributeSpecification> UpdateAttributeSpecificationAsync(ServiceAttributeSpecification spec)
        {
            var dbSpec = await _dataContext.ServiceAttributeSpecifications.FirstAsync(x => x.Id == spec.Id && x.ServiceTypeId == spec.ServiceTypeId);

            dbSpec.AttributeType = spec.AttributeType;
            dbSpec.Description   = spec.Description;
            dbSpec.Name          = spec.Name;

            await _dataContext.SaveChangesAsync();

            return(dbSpec);
        }