Beispiel #1
0
        private async Task DeleteFromOuterResource(OuterResourceModel outerResourceModel)
        {
            var outerInnerResources = _dbContext.OuterInnerResources
                                      .Where(x => x.OuterResourceId == outerResourceModel.Id)
                                      .ToList();

            await DeleteRelationships(outerInnerResources);
        }
 private async Task CreateFromOuterResource(OuterResourceModel model, List <SiteDto> sites, int eFormId)
 {
     if (model.RelatedInnerResourcesIds != null)
     {
         foreach (var id in model.RelatedInnerResourcesIds)
         {
             var innerResource = _dbContext.InnerResources.SingleOrDefault(x => x.Id == id);
             await CreateRelationships(id, model.Id, innerResource.Name, model.Name, sites, eFormId);
         }
     }
 }
        public async Task <OperationResult> Create(OuterResourceModel model)
        {
            try
            {
                var outerResource = new OuterResource()
                {
                    Name       = model.Name,
                    ExternalId = model.ExternalId
                };

                await outerResource.Create(_dbContext);

                model.Id = outerResource.Id;

                if (model.RelatedInnerResourcesIds != null)
                {
                    foreach (var innerResourceId in model.RelatedInnerResourcesIds)
                    {
                        var macth = await _dbContext.OuterInnerResources.SingleOrDefaultAsync(x =>
                                                                                              x.OuterResourceId == model.Id &&
                                                                                              x.InnerResourceId == innerResourceId);

                        if (macth == null)
                        {
                            var
                                outerInnerResource =
                                new Microting.eFormOuterInnerResourceBase.Infrastructure.Data.Entities.
                                OuterInnerResource
                            {
                                InnerResourceId = innerResourceId,
                                OuterResourceId = model.Id
                            };
                            await outerInnerResource.Create(_dbContext);
                        }
                    }
                    await _bus.SendLocal(new OuterInnerResourceCreate(null, model));
                }

                return(new OperationResult(true,
                                           _localizationService.GetString("OuterResourceCreatedSuccessfully", model.Name)));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationResult(false,
                                           _localizationService.GetString("ErrorCreatingOuterResource")));
            }
        }
 public async Task <OperationResult> UpdateArea([FromBody] OuterResourceModel model)
 {
     return(await _outerResourceService.Update(model));
 }
        public async Task <OperationResult> Update(OuterResourceModel model)
        {
            try
            {
                var outerResource =
                    await _dbContext.OuterResources.SingleOrDefaultAsync(x => x.Id == model.Id);

                outerResource.ExternalId = model.ExternalId;
                outerResource.Name       = model.Name;
                await outerResource.Update(_dbContext);

                var
                    outerInnerResources =
                    await _dbContext.OuterInnerResources.Where(x =>
                                                               x.OuterResourceId == outerResource.Id &&
                                                               x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync();

                var requestedInnerResourceIds = model.RelatedInnerResourcesIds;
                var deployedInnerResourceIds  = new List <int>();
                var toBeDeployed = new List <int>();

                foreach (var outerInnerResource in outerInnerResources)
                {
                    deployedInnerResourceIds.Add(outerInnerResource.InnerResourceId);

                    if (!model.RelatedInnerResourcesIds.Contains(outerInnerResource.InnerResourceId))
                    {
                        await outerInnerResource.Delete(_dbContext);

                        await _bus.SendLocal(new OuterInnerResourceUpdate(outerInnerResource.Id));
                    }
                }

                if (requestedInnerResourceIds.Count != 0)
                {
                    toBeDeployed.AddRange(requestedInnerResourceIds.Where(x =>
                                                                          !deployedInnerResourceIds.Contains(x)));
                }

                foreach (var innerResourceId in toBeDeployed)
                {
                    var innerResource = _dbContext.InnerResources.SingleOrDefault(x =>
                                                                                  x.Id == innerResourceId);
                    if (innerResource != null)
                    {
                        var
                            outerInnerResource = await _dbContext.OuterInnerResources.SingleOrDefaultAsync(x =>
                                                                                                           x.OuterResourceId == outerResource.Id &&
                                                                                                           x.InnerResourceId == innerResourceId);

                        if (outerInnerResource == null)
                        {
                            outerInnerResource =
                                new Microting.eFormOuterInnerResourceBase.Infrastructure.Data.Entities.OuterInnerResource()
                            {
                                InnerResourceId = innerResourceId,
                                OuterResourceId = outerResource.Id
                            };
                            await outerInnerResource.Create(_dbContext);
                        }
                        else
                        {
                            outerInnerResource.WorkflowState = Constants.WorkflowStates.Created;
                            await outerInnerResource.Update(_dbContext);
                        }

                        await _bus.SendLocal(new OuterInnerResourceUpdate(outerInnerResource.Id));
                    }
                }
                return(new OperationResult(true, _localizationService.GetString("OuterResourceUpdatedSuccessfully")));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationResult(false,
                                           _localizationService.GetString("ErrorUpdatingOuterResource")));
            }
        }
Beispiel #6
0
 public OuterInnerResourceDelete(InnerResourceModel innerResourceModel, OuterResourceModel outerResourceModel)
 {
     InnerResourceModel = innerResourceModel;
     OuterResourceModel = outerResourceModel;
 }