// 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 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 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 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)); } }