示例#1
0
 public bool Import(Guid solutionId, IList <Domain.WebResource> webResources)
 {
     if (webResources.NotEmpty())
     {
         foreach (var item in webResources)
         {
             var entity = _webResourceFinder.FindById(item.WebResourceId, false);
             if (entity != null)
             {
                 entity.Content     = item.Content;
                 entity.Description = item.Description;
                 entity.Name        = item.Name;
                 _webResourceUpdater.Update(entity);
             }
             else
             {
                 item.ComponentState = 0;
                 item.SolutionId     = solutionId;
                 item.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
                 item.OrganizationId = _appContext.OrganizationId;
                 _webResourceCreater.Create(item);
             }
         }
     }
     return(true);
 }
示例#2
0
        public async Task <IActionResult> CreateWebResource(EditWebResourceModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = new WebResource.Domain.WebResource();
                model.CopyTo(entity);
                entity.WebResourceId  = Guid.NewGuid();
                entity.CreatedBy      = CurrentUser.SystemUserId;
                entity.CreatedOn      = DateTime.Now;
                entity.OrganizationId = CurrentUser.OrganizationId;
                if (model.WebResourceType == WebResourceType.Picture)
                {
                    if (model.ResourceFile != null && model.ResourceFile.Length > 0)
                    {
                        byte[] bytes = new byte[model.ResourceFile.Length];
                        using (Stream s = new MemoryStream())
                        {
                            await model.ResourceFile.CopyToAsync(s).ConfigureAwait(false);

                            await s.ReadAsync(bytes, 0, bytes.Length).ConfigureAwait(false);

                            entity.Content = _webResourceContentCoder.CodeEncode(bytes);
                        }
                    }
                    else
                    {
                        return(CreateFailure(T["webresource_content_empty"]));
                    }
                }
                else
                {
                    if (model.Type == 0)
                    {
                        if (model.ResourceFile != null && model.ResourceFile.Length > 0)
                        {
                            byte[] bytes = new byte[model.ResourceFile.Length];
                            using (Stream s = new MemoryStream())
                            {
                                await model.ResourceFile.CopyToAsync(s).ConfigureAwait(false);

                                await s.ReadAsync(bytes, 0, bytes.Length).ConfigureAwait(false);

                                entity.Content = _webResourceContentCoder.CodeEncode(bytes);
                            }
                        }
                    }
                    else if (model.Type == 1)
                    {
                        if (model.Content.IsNotEmpty())
                        {
                            entity.Content = _webResourceContentCoder.CodeEncode(model.Content);
                        }
                    }
                    if (entity.Content.IsEmpty())
                    {
                        return(CreateFailure(T["webresource_content_empty"]));
                    }
                }

                _webResourceCreater.Create(entity);
                return(CreateSuccess(new { id = entity.WebResourceId }));
            }
            return(CreateFailure(GetModelErrors()));
        }