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