Esempio n. 1
0
        public async Task <IActionResult> FromLink([FromForm] ImageLinkViewModel model)
        {
            string FilePath;

            using (var client = new HttpClient())
            {
                using (var result = await client.GetAsync(model.Url))
                {
                    if (result.IsSuccessStatusCode)
                    {
                        byte[] a = await result.Content.ReadAsByteArrayAsync();

                        if (a.Length > (model.Size * 1024))
                        {
                            throw new FileLoadException($"حجم تصویر وارد شده نباید بیش از {model.Size} کیلوبایت باشد");
                        }
                    }
                }
            }
            using (WebClient client = new WebClient())
            {
                var FileName = $"{Guid.NewGuid()}.jpg";
                FilePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Img", FileName);
                client.DownloadFile(new Uri(model.Url), FilePath);
            }
            return(Ok(FilePath));
        }
Esempio n. 2
0
        public static ArticlePartialViewModel CreateArticlePartialViewModel(ArticleItem articleItem, ArticleModule articleModule,
            ArrayList categoryNamesList, ArrayList attributeNamesList, PortalType portalType,
            Dictionary<string, string> resources, int clientId, int portalId, string adminURL)
        {
            ArticlePartialViewModel articlePartialViewModel = new ArticlePartialViewModel();
            DataConfigurationRepository dataConfigurationRepository = new
                            DataConfigurationRepository(HttpContext.Current.Application["KBDataPath"].ToString(), HttpContext.Current.Application["KBInstallPath"].ToString());
            articlePartialViewModel.Resources = resources;
            articlePartialViewModel.ArticleItem = articleItem;
            articlePartialViewModel.clientId = clientId;
            articlePartialViewModel.portalId = portalId;
            if (articleModule != null)
            {
                articlePartialViewModel.ArticleConfiguration = articleModule;
            }
            else
            {
                //---- set defaults ------

            }
            List<BreadcrumbViewModel> categories = new List<BreadcrumbViewModel>();
            foreach (List<string> names in categoryNamesList)
            {
                BreadcrumbViewModel itemList = new BreadcrumbViewModel();
                itemList.NavigationList = new List<SelectListItem>();
                foreach (string name in names)
                {
                    itemList.NavigationList.Add(new SelectListItem() { Text = name, Value = string.Empty, Selected = false });
                }
                categories.Add(itemList);
            }
            articlePartialViewModel.Categories = categories;
            articlePartialViewModel.Attributes = new List<BreadcrumbViewModel>();
            List<BreadcrumbViewModel> attr = new List<BreadcrumbViewModel>();
            foreach (List<string> names in attributeNamesList)
            {
                BreadcrumbViewModel itemList = new BreadcrumbViewModel();
                itemList.NavigationList = new List<SelectListItem>();
                foreach (string name in names)
                {
                    itemList.NavigationList.Add(new SelectListItem() { Text = name, Value = string.Empty, Selected = false });
                }
                attr.Add(itemList);
            }
            articlePartialViewModel.Attributes = attr;
            articlePartialViewModel.ImageLinks = new List<ImageLinkViewModel>();
            ImageLinkViewModel imageLinkViewModel;

            //check Favorite is enabled
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleFavoriteDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = (articlePartialViewModel.ArticleItem.Favorite == true &&
                    (portalType != PortalType.Open && portalType != PortalType.Registration)) ?
                    @Utilities.GetImageUrl(clientId, portalId, "favoriteactive.png") : @Utilities.GetImageUrl(clientId, portalId, "favorite.png"),
                                                                Link = "/Article/FavoriteArticle/" + clientId + "/" + portalId,
                                                                Title = Utilities.GetResourceText(resources, "CONTROLS_FAVORITELABEL"),
                                                                ToggleIcon = (articlePartialViewModel.ArticleItem.Favorite == true ||
                                                                portalType == PortalType.Open || portalType == PortalType.Registration) ?
                                                                @Utilities.GetImageUrl(clientId, portalId, "favorite.png") :
                                                                @Utilities.GetImageUrl(clientId, portalId, "favoriteactive.png")
                };
                imageLinkViewModel.Id = "favorites";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }

            //check Subscription is enabled
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleSubscribeDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "subscribe.png"),
                    Link = "", Title = Utilities.GetResourceText(resources, "CONTROLS_SUBSCRIBELABEL"),
                    ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "subscribe_selected.png") };
                // imageLinkViewModel = new ImageLinkViewModel() { Icon = (articlesViewModel.ArticlePartialViewModel.ArticleItem.SubscriptionStatus == true && (_portal.PortalType != PortalType.Open && _portal.PortalType != PortalType.Registration)) ? @Utilities.GetImageUrl(clientId, portalId, "subscribe_select.png") : @Utilities.GetImageUrl(clientId, portalId, "subscribe.png"), Link = "/Article/ToggleArticleSubscription/" + clientId + "/" + portalId, Title = Utilities.GetResourceText(resources, "CONTROLS_SUBSCRIBELABEL"), ToggleIcon = (articlesViewModel.ArticlePartialViewModel.ArticleItem.SubscriptionStatus == true || _portal.PortalType == PortalType.Open || _portal.PortalType == PortalType.Registration) ? @Utilities.GetImageUrl(clientId, portalId, "subscribe.png") : @Utilities.GetImageUrl(clientId, portalId, "subscribe.png") };
                //imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "subscribe.png"), Link = "", Title = Utilities.GetResourceText(resources,"CONTROLS_SUBSCRIBELABEL"), ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "subscribe.png") };
                imageLinkViewModel.Id = "subscribe";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }
            //Check share is enabled
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleShareDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "share.png"),
                    Link = "", Title = Utilities.GetResourceText(resources, "CONTROLS_SHARELABEL"),
                    ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "share_selected.png") };
                imageLinkViewModel.Id = "share";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleEditDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "edit.png"),
                                                                Link = adminURL + "/index.aspx?aid=",
                                                                Title = Utilities.GetResourceText(resources, "CONTROLS_EDITLABEL"),
                    ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "edit.png") };
                imageLinkViewModel.Id = "edit";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }
            articlePartialViewModel.Attachments = articleItem.Attachments;
            return articlePartialViewModel;
        }