示例#1
0
        public ChangeActivityOutput <ConditionTypeDto, long> ChangeActivity(ChangeActivityInput input)
        {
            ConditionTypeRepository.Includes.Add(r => r.LastModifierUser);
            ConditionTypeRepository.Includes.Add(r => r.CreatorUser);

            ConditionType conditionTypeEntity = ConditionTypeRepository.Get(input.EntityId);

            if (conditionTypeEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"ConditionType\"");
            }

            if (!ConditionTypePolicy.CanChangeActivityForEntity(conditionTypeEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionChangeActivityDenied, "\"ConditionType\"");
            }

            conditionTypeEntity.IsActive = input.IsActive == null ? !conditionTypeEntity.IsActive : (bool)input.IsActive;

            ConditionTypeDto newConditionTypeDto = (conditionTypeEntity).MapTo <ConditionTypeDto>();

            ConditionTypeRepository.Update(conditionTypeEntity);

            ConditionTypeRepository.Includes.Clear();

            return(new ChangeActivityOutput <ConditionTypeDto, long>()
            {
                Entity = newConditionTypeDto
            });
        }
示例#2
0
        public UpdateOutput <ConditionTypeDto, long> Update(UpdateInput <ConditionTypeDto, long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            ConditionType newConditionTypeEntity = input.Entity.MapTo <ConditionType>();

            if (newConditionTypeEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"ConditionType\"");
            }

            if (!ConditionTypePolicy.CanUpdateEntity(newConditionTypeEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"ConditionType\"");
            }

            ConditionTypeRepository.Includes.Add(r => r.LastModifierUser);
            ConditionTypeRepository.Includes.Add(r => r.CreatorUser);

            ConditionTypeRepository.Update(newConditionTypeEntity);
            ConditionTypeDto newConditionTypeDto = (ConditionTypeRepository.Get(newConditionTypeEntity.Id)).MapTo <ConditionTypeDto>();

            ConditionTypeRepository.Includes.Clear();

            return(new UpdateOutput <ConditionTypeDto, long>()
            {
                UpdatedEntity = newConditionTypeDto
            });
        }
示例#3
0
        public CreateOutput <ConditionTypeDto, long> Create(CreateInput <ConditionTypeDto, long> input)
        {
            throw new NotSupportedException("This method is implemented but it is not safely to use it.");

            ConditionType newConditionTypeEntity = input.Entity.MapTo <ConditionType>();

            newConditionTypeEntity.IsDefault = false;
            newConditionTypeEntity.IsActive  = true;

            if (!ConditionTypePolicy.CanCreateEntity(newConditionTypeEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"ConditionType\"");
            }

            ConditionTypeRepository.Includes.Add(r => r.LastModifierUser);
            ConditionTypeRepository.Includes.Add(r => r.CreatorUser);

            ConditionTypeDto newConditionTypeDto = (ConditionTypeRepository.Insert(newConditionTypeEntity)).MapTo <ConditionTypeDto>();

            ConditionTypeRepository.Includes.Clear();

            return(new CreateOutput <ConditionTypeDto, long>()
            {
                CreatedEntity = newConditionTypeDto
            });
        }
示例#4
0
        public RetrieveOutput <ConditionTypeDto, long> Retrieve(RetrieveConditionTypeInput input)
        {
            if (input.IsActive ?? true)
            {
                UowManager.Current.EnableFilter(Filters.IPassivableFilter);
            }

            ConditionTypeRepository.Includes.Add(r => r.LastModifierUser);
            ConditionTypeRepository.Includes.Add(r => r.CreatorUser);

            IList <ConditionType> conditionTypeEntities = ConditionTypeRepository.GetAll()
                                                          .WhereIf(input.Id != null, r => r.Id == input.Id)
                                                          .WhereIf(!String.IsNullOrEmpty(input.Name), r => r.Name.ToLower().Contains(input.Name.ToLower()))
                                                          .ToList();

            if (conditionTypeEntities.Count != 1)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"ConditionType\"");
            }

            if (!ConditionTypePolicy.CanRetrieveEntity(conditionTypeEntities.Single()))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionRetrieveDenied, "\"ConditionType\"");
            }

            ConditionTypeDto conditionTypeEntity = conditionTypeEntities.Single().MapTo <ConditionTypeDto>();

            ConditionTypeRepository.Includes.Clear();

            return(new RetrieveOutput <ConditionTypeDto, long>()
            {
                RetrievedEntity = conditionTypeEntity
            });
        }
示例#5
0
        public async Task <IActionResult> GetByKey([FromRoute] Guid tenantId, [FromRoute] int code)
        {
            ConditionTypeDto conditionTypeDto = await this.conditionTypeService.GetBy(tenantId, code);

            if (conditionTypeDto != null)
            {
                return(this.Ok(conditionTypeDto));
            }

            return(this.NotFound("A condition type w/ the given tenant id and code was not found"));
        }
示例#6
0
        public async Task <IActionResult> Add([FromRoute] Guid tenantId, [FromBody] CreateConditionTypeDto conditionTypeDto)
        {
            ConditionTypeDto addedConditionTypeDto = await this.conditionTypeService.Add(conditionTypeDto.ToConditionTypeDto(tenantId));

            if (addedConditionTypeDto.Code != default(int))
            {
                return(this.CreatedAtRoute("get-condition-type", new { code = addedConditionTypeDto.Code }, addedConditionTypeDto));
            }

            return(this.BadRequest());
        }
示例#7
0
        public async Task <IActionResult> Update([FromRoute] Guid tenantId, [FromRoute] int code, [FromBody] UpdateConditionTypeDto updateConditionTypeDto)
        {
            try
            {
                ConditionTypeDto conditionTypeDto = await this.conditionTypeService.Update(updateConditionTypeDto.ToConditionTypeDto(tenantId, code));

                return(this.Ok(conditionTypeDto));
            }
            catch (NotFoundException)
            {
                return(this.NotFound("A condition type w/ the given id was not found"));
            }
        }
示例#8
0
        public async Task <ConditionTypeDto> Update(ConditionTypeDto conditionTypeDto)
        {
            ConditionTypeKey key           = ConditionTypeKey.New(conditionTypeDto.TenantId, conditionTypeDto.Code);
            ConditionType    conditionType = await this.conditionTypeRepository.GetById(key);

            if (conditionType == null)
            {
                throw new NotFoundException(FormattableString.Invariant($"{nameof(ConditionType)} was not found. Key = {key}"));
            }

            conditionType.Name        = conditionTypeDto.Name;
            conditionType.Description = conditionTypeDto.Description;

            return(await this.conditionTypeRepository.Update(conditionType)
                   .ContinueWith(tenantTask =>
            {
                tenantTask.GetAwaiter().GetResult();
                return this.ConvertToDto(conditionType);
            }));
        }
示例#9
0
        public async Task <ConditionTypeDto> Add(ConditionTypeDto conditionTypeDto)
        {
            if (conditionTypeDto == null)
            {
                throw new ArgumentNullException(nameof(conditionTypeDto));
            }

            ConditionType conditionType = this.conditionTypeFactory.CreateConditionType(
                conditionTypeDto.TenantId,
                conditionTypeDto.Code,
                conditionTypeDto.DataTypeCode.AsDataTypeCode(),
                conditionTypeDto.Name,
                conditionTypeDto.Description);

            await this.conditionTypeRepository.Add(conditionType);

            conditionTypeDto.Code     = conditionType.Key.Code;
            conditionTypeDto.TenantId = conditionType.Key.TenantId;

            return(conditionTypeDto);
        }