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));
            }
        }
Example #2
0
        // Site Category Converter
        public static SiteCategoryDTO ToDto(this Community_Showcase_SiteCategory item)
        {
            SiteCategoryDTO dto = new SiteCategoryDTO()
            {
                id          = item.id,
                site_id     = item.site_id,
                category_id = item.category_id,

                site_name     = item.Community_Showcase_Site.name,
                category_name = item.Community_Showcase_Category.name
            };

            return(dto);
        }
Example #3
0
        public static Community_Showcase_SiteCategory ToItem(this SiteCategoryDTO dto, Community_Showcase_SiteCategory item)
        {
            if (item == null)
            {
                item = new Community_Showcase_SiteCategory();
            }

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

            item.id          = dto.id;
            item.site_id     = dto.site_id;
            item.category_id = dto.category_id;

            return(item);
        }
        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_SiteCategories(Community_Showcase_SiteCategory entity)
 {
     this.SendPropertyChanging();
     entity.Community_Showcase_Category = null;
 }
 partial void DeleteCommunity_Showcase_SiteCategory(Community_Showcase_SiteCategory instance);
 partial void InsertCommunity_Showcase_SiteCategory(Community_Showcase_SiteCategory instance);