public OperationsGroupComplex ConvertToDALEntity(ApiOperationsGroup businessEntity)
        {
            if (businessEntity?.User == null || businessEntity.Frequency == null || businessEntity.Importance == null)
            {
                throw new ArgumentException(Properties.strings.ExWrongParameters);
            }
            var result1 = new DalOperationsGroup(businessEntity.Id, businessEntity.User.Id, businessEntity.Description, businessEntity.Frequency.Id, businessEntity.Importance.Id, businessEntity.Date);

            result1.IsDirty           = businessEntity.IsDirty;
            result1.IsMarkForDeletion = businessEntity.IsMarkForDeletion;

            var result2 = new List <DalOperationsGroupTags>();

            foreach (var tag in businessEntity.Tags)
            {
                var newTag = new DalOperationsGroupTags(tag.Id, businessEntity.Id, tag.Tag.Id);
                newTag.IsDirty           = tag.IsDirty;
                newTag.IsMarkForDeletion = tag.IsMarkForDeletion;
                result2.Add(newTag);
            }

            var tmp = _operationMapper.ConvertToDALEntitiesCollection(businessEntity.Operations);

            return(new OperationsGroupComplex(result1, result2, tmp));
        }
        public IActionResult Post([FromBody] ApiOperationsGroup group)
        { //TODO: validators
            try
            {
                _repository.UpdateOperationsGroupComplex(group);

                return(Created($"api/operationsgroups/{1}", group)); //TODO: not hardcode 1
            }
            catch (Exception)
            {
                return(BadRequest("Failed"));
            }
        }
        public ApiOperationsGroup ConvertToApiEntity(DalOperationsGroup dataEntity)
        {
            var frequency  = _frequencies.First(f => f.Id == dataEntity.FrequencyId);
            var importance = _importances.First(f => f.Id == dataEntity.ImportanceId);
            var operations = _operations.Where(o => o.GroupId == dataEntity.Id).ToArray();

            var dalTags = _dalRelations.Where(t => t.OperationsGroupId == dataEntity.Id);
            var tags    = _tagMapper.ConvertToApiEntitiesCollection(dalTags).ToArray();

            var result = new ApiOperationsGroup(dataEntity.Id, _user, dataEntity.Description, frequency, importance, dataEntity.Date, tags, operations);

            result.UpdateAmount(_transactionTypes);
            result.IsDirty           = dataEntity.IsDirty;
            result.IsMarkForDeletion = dataEntity.IsMarkForDeletion;
            return(result);
        }
Exemplo n.º 4
0
        public void UpdateOperationsGroupComplex(ApiOperationsGroup group)
        {
            var dalObjects             = OperationsGroupMapper.ConvertToDALEntity(group);
            var dalOperationsGroup     = dalObjects.Group;
            var dalOperationsGroupTags = dalObjects.Tags;
            var dalOperations          = dalObjects.Operations;

            var id = Update(dalOperationsGroup, OperationsGroupAdapter);

            foreach (var dalOperationsGroupTag in dalOperationsGroupTags)
            {
                dalOperationsGroupTag.UpdateOperationsGroupId(id.Value);
                Update(dalOperationsGroupTag, OperationsGroupRelationAdapter);
            }
            foreach (var dalOperation in dalOperations)
            {
                UpdateOperationComplex(dalOperation);
            }
        }
Exemplo n.º 5
0
 public async void UpdateOperationsGroupComplex(ApiOperationsGroup group)
 {
     _apiAdapter.UpdateOperationsGroupComplex(group);
     await Task.Run(() => ReloadData());
 }