public string CreateThumbnail(Community_Showcase_Site site, string home_directory_map_path, string home_directory)
        {
            string thumbnail = "";

            int width  = 1980;
            int height = 1080;

            // create directory if necessary
            DirectoryInfo di = new DirectoryInfo(home_directory_map_path + "\\DNN_Showcase");

            if (!di.Exists)
            {
                di.Create();
            }

            try
            {
                thumbnail = home_directory_map_path + "/DNN_Showcase/" + "Site" + site.id.ToString("00000") + ".jpg";

                //var image = WebsiteThumbnail.Capture(site.url, width, height);
                //image.Save(thumbnail);

                //thumbnail = "/Portals/" + PortalSettings.PortalId.ToString() + "/DNN_Showcase/" + "Site" + site.id.ToString("00000") + ".jpg";
            }
            catch (Exception ex)
            {
                throw ex;
                // error
            }

            return(thumbnail);
        }
        // Site Converter
        public static SiteDTO ToDto(this Community_Showcase_Site item)
        {
            SiteDTO dto = new SiteDTO()
            {
                id           = item.id,
                name         = item.name,
                created_date = item.created_date,
                description  = item.description,
                is_active    = item.is_active,
                thumbnail    = item.thumbnail,
                url          = item.url,
                user_id      = item.user_id
            };

            dto.site_categories = new List <SiteCategoryDTO>();
            foreach (Community_Showcase_SiteCategory site_category in item.Community_Showcase_SiteCategories)
            {
                SiteCategoryDTO siteCategoryDTO = new SiteCategoryDTO()
                {
                    category_id   = site_category.category_id,
                    site_id       = site_category.site_id,
                    site_name     = site_category.Community_Showcase_Site.name,
                    category_name = site_category.Community_Showcase_Category.name
                };
                dto.site_categories.Add(siteCategoryDTO);
            }


            return(dto);
        }
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                Community_Showcase_Site item = dc.Community_Showcase_Sites.Where(i => i.id == id).SingleOrDefault();

                if (item == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                dc.Community_Showcase_Sites.DeleteOnSubmit(item);
                dc.SubmitChanges();

                var      file_path = System.Web.Hosting.HostingEnvironment.MapPath(item.thumbnail);
                FileInfo fi        = new FileInfo(file_path);
                if (fi.Exists)
                {
                    fi.Delete();
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public HttpResponseMessage Put(SiteDTO dto)
        {
            try
            {
                Community_Showcase_Site site = dc.Community_Showcase_Sites.Where(i => i.id == dto.id).SingleOrDefault();
                site = dto.ToItem(site);

                // categories
                dc.Community_Showcase_SiteCategories.DeleteAllOnSubmit(site.Community_Showcase_SiteCategories);
                foreach (SiteCategoryDTO siteCategoryDTO in dto.site_categories)
                {
                    Community_Showcase_SiteCategory site_category = new Community_Showcase_SiteCategory()
                    {
                        category_id = siteCategoryDTO.category_id
                    };
                    site.Community_Showcase_SiteCategories.Add(site_category);
                }

                var valid = ValidateSite(site);
                if (valid)
                {
                    // move temp image
                    var      old_path = System.Web.Hosting.HostingEnvironment.MapPath(site.thumbnail);
                    FileInfo fi       = new FileInfo(old_path);
                    if (fi.Exists)
                    {
                        string file_path = "/DNN_Showcase/" + site.id.ToString("00000") + ".jpg";
                        string new_path  = PortalSettings.HomeDirectoryMapPath + file_path;

                        FileInfo old_file = new FileInfo(new_path);
                        {
                            if (old_file.Exists)
                            {
                                old_file.Delete();
                            }
                        }

                        fi.MoveTo(new_path);
                        site.thumbnail = PortalSettings.HomeDirectory + file_path;
                    }

                    dc.SubmitChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, dto));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotAcceptable, dto));
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public HttpResponseMessage Get(int id)
        {
            try
            {
                Community_Showcase_Site item = dc.Community_Showcase_Sites.Where(i => i.id == id).SingleOrDefault();

                if (item == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, item.ToDto()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public static Community_Showcase_Site ToItem(this SiteDTO dto, Community_Showcase_Site item)
        {
            if (item == null)
            {
                item = new Community_Showcase_Site();
            }

            if (dto == null)
            {
                return(item);
            }

            item.id           = dto.id;
            item.name         = dto.name;
            item.created_date = dto.created_date;
            item.description  = dto.description;
            item.is_active    = dto.is_active;
            item.thumbnail    = dto.thumbnail;
            item.url          = dto.url;
            item.user_id      = item.user_id;

            return(item);
        }
        public bool ValidateSite(Community_Showcase_Site site)
        {
            bool valid = true;

            // first validate if the URL exists
            valid = ValidateURL(site.url);
            if (!valid && site.url.IndexOf("https://") != -1)
            {
                // if it was a secure URL that failed, try the unsecure version
                valid = ValidateURL(site.url.Replace("https://", "http://"));
            }

            Uri    objUri        = new Uri(site.url);
            string strValidation = objUri.Scheme + "://" + objUri.Host + "/js/dnn.js";

            valid = ValidateURL(strValidation);
            if (!valid && strValidation.IndexOf("https://") != -1)
            {
                valid = ValidateURL(strValidation.Replace("https://", "http://"));
            }

            return(valid);
        }
        public HttpResponseMessage Post(SiteDTO dto)
        {
            try
            {
                Community_Showcase_Site site = dto.ToItem(null);

                int user_id = DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo().UserID;

                site.user_id      = user_id;
                site.created_date = DateTime.Now;

                dc.Community_Showcase_Sites.InsertOnSubmit(site);

                // categories
                foreach (SiteCategoryDTO siteCategoryDTO in dto.site_categories)
                {
                    Community_Showcase_SiteCategory site_category = new Community_Showcase_SiteCategory()
                    {
                        category_id = siteCategoryDTO.category_id
                    };
                    site.Community_Showcase_SiteCategories.Add(site_category);
                }

                var valid = ValidateSite(site);
                if (valid)
                {
                    dc.SubmitChanges();

                    // move temp image
                    var      old_path = System.Web.Hosting.HostingEnvironment.MapPath(site.thumbnail);
                    FileInfo fi       = new FileInfo(old_path);
                    if (fi.Exists)
                    {
                        string file_path = "/DNN_Showcase/" + site.id.ToString("00000") + ".jpg";
                        string new_path  = PortalSettings.HomeDirectoryMapPath + file_path;

                        FileInfo old_file = new FileInfo(new_path);
                        {
                            if (old_file.Exists)
                            {
                                old_file.Delete();
                            }
                        }

                        fi.MoveTo(new_path);
                        site.thumbnail = PortalSettings.HomeDirectory + file_path;
                    }

                    dc.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, dto));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotAcceptable));
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
 private void detach_Community_Showcase_Sites(Community_Showcase_Site entity)
 {
     this.SendPropertyChanging();
     entity.User = null;
 }
 partial void DeleteCommunity_Showcase_Site(Community_Showcase_Site instance);
 partial void UpdateCommunity_Showcase_Site(Community_Showcase_Site instance);
 partial void InsertCommunity_Showcase_Site(Community_Showcase_Site instance);