Esempio n. 1
0
 public IEnumerable <IMovementStateDto> GetAll(string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null)
 {
     try {
         IEnumerable <IMovementState> states = null;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             states = _movementApplicationService.Get(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                              , n => (MovementMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? MovementMetadata.Instance.FilteringPropertyAliasDictionary[n] : n))
                                                      , MovementsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         else
         {
             states = _movementApplicationService.Get(MovementsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs())
                                                      , MovementsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         var stateDtos = new List <IMovementStateDto>();
         foreach (var s in states)
         {
             var dto = s is MovementStateDtoWrapper ? (MovementStateDtoWrapper)s : new MovementStateDtoWrapper(s);
             if (String.IsNullOrWhiteSpace(fields))
             {
                 dto.AllFieldsReturned = true;
             }
             else
             {
                 dto.ReturnedFieldsString = fields;
             }
             stateDtos.Add(dto);
         }
         return(stateDtos);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 2
0
 public void Patch(string id, [FromBody] MergePatchMovementDto value)
 {
     try {
         MovementsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _movementApplicationService.When(value as IMergePatchMovement);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 3
0
 public MovementStateCreatedOrMergePatchedOrDeletedDto GetStateEvent(string id, long version)
 {
     try {
         var idObj = id;
         var conv  = new MovementStateEventDtoConverter();
         var se    = _movementApplicationService.GetEvent(idObj, version);
         return(se == null ? null : conv.ToMovementStateEventDto(se));
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 4
0
 public void Delete(string id, string commandId, string version, string requesterId = default(string))
 {
     try {
         var value = new DeleteMovementDto();
         value.CommandId   = commandId;
         value.RequesterId = requesterId;
         value.Version     = (long)Convert.ChangeType(version, typeof(long));
         MovementsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _movementApplicationService.When(value as IDeleteMovement);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 5
0
 public IMovementLineStateDto GetMovementLine(string movementDocumentNumber, string lineNumber)
 {
     try {
         var state = (MovementLineState)_movementApplicationService.GetMovementLine(movementDocumentNumber, lineNumber);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new MovementLineStateDtoWrapper(state);
         stateDto.AllFieldsReturned = true;
         return(stateDto);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 6
0
        public HttpResponseMessage Post([FromBody] CreateMovementDto value)
        {
            try {
                if (value.DocumentNumber == default(string))
                {
                    throw DomainError.Named("nullId", "Aggregate Id in cmd is null, aggregate name: {0}.", "Movement");
                }
                _movementApplicationService.When(value as ICreateMovement);
                var idObj = value.DocumentNumber;

                return(Request.CreateResponse <string>(HttpStatusCode.Created, idObj));
            } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Esempio n. 7
0
 public void DocumentAction(string id, [FromBody] MovementCommandDtos.DocumentActionRequestContent content)
 {
     try {
         var cmd   = content.ToDocumentAction();
         var idObj = id;
         if (cmd.DocumentNumber == null)
         {
             cmd.DocumentNumber = idObj;
         }
         else if (!cmd.DocumentNumber.Equals(idObj))
         {
             throw DomainError.Named("inconsistentId", "Argument Id {0} NOT equals body Id {1}", id, cmd.DocumentNumber);
         }
         _movementApplicationService.When(cmd);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 8
0
 public long GetCount(string filter = null)
 {
     try
     {
         long count = 0;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             count = _movementApplicationService.GetCount(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                                  , n => (MovementMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? MovementMetadata.Instance.FilteringPropertyAliasDictionary[n] : n)));
         }
         else
         {
             count = _movementApplicationService.GetCount(MovementsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()));
         }
         return(count);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 9
0
 public IEnumerable <PropertyMetadataDto> GetMetadataFilteringFields()
 {
     try {
         var filtering = new List <PropertyMetadataDto>();
         foreach (var p in MovementMetadata.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 = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 10
0
        public void Put(string id, [FromBody] CreateOrMergePatchOrDeleteMovementDto value)
        {
            try {
                // ///////////////////////////////
                if (value.Version != default(long))
                {
                    value.CommandType = CommandType.MergePatch;
                    MovementsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                    _movementApplicationService.When(value as IMergePatchMovement);
                    return;
                }
                // ///////////////////////////////

                MovementsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                _movementApplicationService.When(value as ICreateMovement);
            } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Esempio n. 11
0
 public IEnumerable <IMovementLineStateDto> GetMovementLines(string movementDocumentNumber)
 {
     try {
         var states = _movementApplicationService.GetMovementLines(movementDocumentNumber);
         if (states == null)
         {
             return(null);
         }
         var stateDtos = new List <IMovementLineStateDto>();
         foreach (var s in states)
         {
             var dto = s is MovementLineStateDtoWrapper ? (MovementLineStateDtoWrapper)s : new MovementLineStateDtoWrapper((IMovementLineState)s);
             dto.AllFieldsReturned = true;
             stateDtos.Add(dto);
         }
         return(stateDtos);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Esempio n. 12
0
 public IMovementStateDto Get(string id, string fields = null)
 {
     try {
         var idObj = id;
         var state = _movementApplicationService.Get(idObj);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new MovementStateDtoWrapper(state);
         if (String.IsNullOrWhiteSpace(fields))
         {
             stateDto.AllFieldsReturned = true;
         }
         else
         {
             stateDto.ReturnedFieldsString = fields;
         }
         return(stateDto);
     } catch (Exception ex) { var response = MovementsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }