public IEnumerable <IDamageTypeStateDto> GetAll(string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null) { try { IEnumerable <IDamageTypeState> states = null; if (!String.IsNullOrWhiteSpace(filter)) { states = _damageTypeApplicationService.Get(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver() , n => (DamageTypeMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? DamageTypeMetadata.Instance.FilteringPropertyAliasDictionary[n] : n)) , DamageTypesControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } else { states = _damageTypeApplicationService.Get(DamageTypesControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()) , DamageTypesControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } var stateDtos = new List <IDamageTypeStateDto>(); foreach (var s in states) { var dto = s is DamageTypeStateDtoWrapper ? (DamageTypeStateDtoWrapper)s : new DamageTypeStateDtoWrapper(s); if (String.IsNullOrWhiteSpace(fields)) { dto.AllFieldsReturned = true; } else { dto.ReturnedFieldsString = fields; } stateDtos.Add(dto); } return(stateDtos); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public void Patch(string id, [FromBody] MergePatchDamageTypeDto value) { try { DamageTypesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value); _damageTypeApplicationService.When(value as IMergePatchDamageType); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public void Delete(string id, string commandId, string version, string requesterId = default(string)) { try { var value = new DeleteDamageTypeDto(); value.CommandId = commandId; value.RequesterId = requesterId; value.Version = (long)Convert.ChangeType(version, typeof(long)); DamageTypesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value); _damageTypeApplicationService.When(value as IDeleteDamageType); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public HttpResponseMessage Post([FromBody] CreateDamageTypeDto value) { try { if (value.DamageTypeId == default(string)) { throw DomainError.Named("nullId", "Aggregate Id in cmd is null, aggregate name: {0}.", "DamageType"); } _damageTypeApplicationService.When(value as ICreateDamageType); var idObj = value.DamageTypeId; return(Request.CreateResponse <string>(HttpStatusCode.Created, idObj)); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public long GetCount(string filter = null) { try { long count = 0; if (!String.IsNullOrWhiteSpace(filter)) { count = _damageTypeApplicationService.GetCount(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver() , n => (DamageTypeMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? DamageTypeMetadata.Instance.FilteringPropertyAliasDictionary[n] : n))); } else { count = _damageTypeApplicationService.GetCount(DamageTypesControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs())); } return(count); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public IEnumerable <PropertyMetadataDto> GetMetadataFilteringFields() { try { var filtering = new List <PropertyMetadataDto>(); foreach (var p in DamageTypeMetadata.Instance.Properties) { if (p.IsFilteringProperty) { var pdto = new PropertyMetadataDto(p.Name, p.TypeName, p.IsFilteringProperty, !String.IsNullOrWhiteSpace(p.SourceChainingName) ? p.SourceChainingName : (!String.IsNullOrWhiteSpace(p.DerivedFrom) ? p.DerivedFrom : p.Name)); filtering.Add(pdto); } } return(filtering); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public void Put(string id, [FromBody] CreateOrMergePatchOrDeleteDamageTypeDto value) { try { // /////////////////////////////// if (value.Version != default(long)) { value.CommandType = CommandType.MergePatch; DamageTypesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value); _damageTypeApplicationService.When(value as IMergePatchDamageType); return; } // /////////////////////////////// DamageTypesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value); _damageTypeApplicationService.When(value as ICreateDamageType); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public IDamageTypeStateDto Get(string id, string fields = null) { try { var idObj = id; var state = _damageTypeApplicationService.Get(idObj); if (state == null) { return(null); } var stateDto = new DamageTypeStateDtoWrapper(state); if (String.IsNullOrWhiteSpace(fields)) { stateDto.AllFieldsReturned = true; } else { stateDto.ReturnedFieldsString = fields; } return(stateDto); } catch (Exception ex) { var response = DamageTypesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }