Exemplo n.º 1
0
            public async Task <AddOrUpdateIdeaResponse> Handle(AddOrUpdateIdeaRequest request)
            {
                var entity = await _context.Ideas
                             .Include(x => x.IdeaDigitalAssets)
                             .Include(x => x.IdeaLinks)
                             .SingleOrDefaultAsync(x => x.Id == request.Idea.Id && x.TenantId == request.TenantId);

                if (entity == null)
                {
                    _context.Ideas.Add(entity = new Idea());
                }

                entity.TenantId = request.TenantId;

                entity.Name = request.Idea.Name;

                entity.IdeationId = request.Idea.IdeationId;

                entity.HtmlBody = request.Idea.HtmlBody;

                entity.HtmlDescription = request.Idea.HtmlDescription;

                entity.UserId = request.UserId;

                entity.IdeaDigitalAssets.Clear();

                foreach (var digitalAsset in request.Idea.DigitalAssets)
                {
                    IdeaDigitalAsset newDigitalAsset = await _context.IdeaDigitalAssets.FindAsync(digitalAsset.Id);

                    if (newDigitalAsset == null)
                    {
                        newDigitalAsset = new IdeaDigitalAsset();
                    }

                    newDigitalAsset.DigitalAssetUrl = digitalAsset.DigitalAssetUrl;

                    entity.IdeaDigitalAssets.Add(newDigitalAsset);
                }

                entity.IdeaLinks.Clear();

                foreach (var link in request.Idea.Links)
                {
                    IdeaLink newLink = await _context.IdeaLinks.FindAsync(link.Id);

                    if (newLink == null)
                    {
                        newLink = new IdeaLink();
                    }

                    entity.IdeaLinks.Add(newLink);
                }

                await _context.SaveChangesAsync();

                return(new AddOrUpdateIdeaResponse());
            }
        public static TModel FromIdeaDigitalAsset <TModel>(IdeaDigitalAsset ideaDigitalAsset) where
        TModel : IdeaDigitalAssetApiModel, new()
        {
            var model = new TModel();

            model.Id              = ideaDigitalAsset.Id;
            model.TenantId        = ideaDigitalAsset.TenantId;
            model.DigitalAssetUrl = ideaDigitalAsset.DigitalAssetUrl;
            return(model);
        }
 public static IdeaDigitalAssetApiModel FromIdeaDigitalAsset(IdeaDigitalAsset ideaDigitalAsset)
 => FromIdeaDigitalAsset <IdeaDigitalAssetApiModel>(ideaDigitalAsset);