public static int UploadResourceData(UploadData data) { int retId = 0; using (ResourcesDataContext dc = new ResourcesDataContext()) { bhdResource r = new bhdResource(); r.name = data.ResourceName; r.description = data.ResourceDescription; r.languageId = data.ResourceLanguageId; r.typeId = data.ResourceTypeId; r.topicId = data.ResourceTopicId; r.uploadDate = DateTime.Now; dc.bhdResources.InsertOnSubmit(r); dc.SubmitChanges(); retId = r.id; bhdResourceFormat rf = new bhdResourceFormat(); rf.formatId = data.ResourceFormatId; rf.resourceId = r.id; dc.bhdResourceFormats.InsertOnSubmit(rf); dc.SubmitChanges(); //bhdResourceRating rr = new bhdResourceRating(); //rr.resourceId = r.id; //rr.rating = 1; //rr.userId = 1; // TODO: Update when the user is passed through. //dc.bhdResourceRatings.InsertOnSubmit(rr); //dc.SubmitChanges(); } return retId; }
public async Task<HttpResponseMessage> Post(int userId) { int returnId = 0; try { using (ResourcesDataContext dc = new ResourcesDataContext()) { Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); ResourceBundle newBundle = JsonConvert.DeserializeObject<ResourceBundle>(jsonstring); bhdResourceBundle rb = new bhdResourceBundle(); rb.name = newBundle.name; rb.description = newBundle.description; rb.userId = userId; rb.isActive = true; dc.bhdResourceBundles.InsertOnSubmit(rb); dc.SubmitChanges(); returnId = rb.bundleId; bhdResourceBundleFile rbf = new bhdResourceBundleFile(); rbf.resourceFileId = newBundle.fileId; rbf.bundleId = returnId; dc.bhdResourceBundleFiles.InsertOnSubmit(rbf); dc.SubmitChanges(); } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. " + ex.Message + ". 400-3"); } return Request.CreateResponse(HttpStatusCode.OK, returnId); }
public static ResourceFile UploadResourceFile(FileData files, int resourceId) { ResourceFile resFileRet = new ResourceFile(); //we get the information using (ResourcesDataContext dc = new ResourcesDataContext()) { //check if we have the file type int typeid = 0; var type = (from d in dc.bhdFileTypes where d.contentType == files.fileType && d.isActive select d).FirstOrDefault(); if (type == null) { bhdFileType ft = new bhdFileType(); ft.contentType = files.fileType; string extension = files.fileName; int pos = extension.LastIndexOf('.'); ft.extension = extension.Substring(pos + 1, extension.Length - (pos + 1)); ft.isActive = true; dc.bhdFileTypes.InsertOnSubmit(ft); dc.SubmitChanges(); typeid = ft.id; } else { typeid = type.id; } bhdFile f = new bhdFile(); f.size = files.fileSize; f.name = files.fileName; f.isActive = true; f.fileTypeId = typeid; dc.bhdFiles.InsertOnSubmit(f); dc.SubmitChanges(); bhdFileData fd = new bhdFileData(); fd.fileId = f.id; fd.data = files.fileData; dc.bhdFileDatas.InsertOnSubmit(fd); dc.SubmitChanges(); bhdResourceFile rf = new bhdResourceFile(); rf.resourceId = resourceId; rf.fileId = f.id; dc.bhdResourceFiles.InsertOnSubmit(rf); dc.SubmitChanges(); ResourceFile tmpFileRes = new ResourceFile(); tmpFileRes.fileid = rf.fileId; tmpFileRes.filename = f.name; resFileRet = tmpFileRes; } return resFileRet; }
public async Task<HttpResponseMessage> Post() { using (ResourcesDataContext dc = new ResourcesDataContext()) { var r = (from d in dc.bhdFeaturedResources select d); foreach (var feature in r) { feature.isActive = false; feature.isFrontPage = false; } dc.SubmitChanges(); var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); if (result != null) { List<FeaturedResourceModel> featuredModel; try { List<FeaturedResourceModel> tmp = (List<FeaturedResourceModel>)JsonConvert.DeserializeObject(jsonstring.ToString(), typeof(List<FeaturedResourceModel>)); featuredModel = tmp; } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } if (featuredModel != null) { foreach (FeaturedResourceModel item in featuredModel) { bhdFeaturedResource feat = new bhdFeaturedResource(); feat.resourceId = item.ResourceId; feat.portalId = item.PortalId; feat.sequence = item.Sequence; feat.startDate = item.sDate; feat.endDate = item.eDate; feat.isActive = true; dc.bhdFeaturedResources.InsertOnSubmit(feat); dc.SubmitChanges(); } } } } return Request.CreateResponse(HttpStatusCode.OK, "Success"); }
public async Task<HttpResponseMessage> Put() { HttpResponseMessage response = new HttpResponseMessage(); var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); ResourceFormat currentFormat; try { currentFormat = JsonConvert.DeserializeObject<ResourceFormat>(jsonstring); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } try { using (ResourcesDataContext db = new ResourcesDataContext()) { if (currentFormat.formatId == 0) { bhdFormat newFormat = new bhdFormat(); newFormat.name = currentFormat.name; newFormat.isActive = currentFormat.active; db.bhdFormats.InsertOnSubmit(newFormat); db.SubmitChanges(); response = Request.CreateResponse(HttpStatusCode.OK, "New Format sucessfully added."); } else { bhdFormat editformat = db.bhdFormats.Single((x) => x.id == currentFormat.formatId); editformat.isActive = currentFormat.active.Value; editformat.name = currentFormat.name; db.SubmitChanges(); response = Request.CreateResponse(HttpStatusCode.OK, "Format sucessfully edited."); } } } catch (Exception ex) { Request.CreateResponse(HttpStatusCode.InternalServerError, ex); } return response; }
public async Task<HttpResponseMessage> Post() { int ResourceId = 0, ratingGiven = 0, userid = 0; HttpResponseMessage response = new HttpResponseMessage(); var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); Dictionary<string, int> currentRating = new Dictionary<string, int>(); try { currentRating = JsonConvert.DeserializeObject<Dictionary<string, int>>(jsonstring); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } if (currentRating != null) { if (currentRating["resourceid"] != null && currentRating["ratingscore"] != null && currentRating["userid"] != null) { using (ResourcesDataContext dc = new ResourcesDataContext()) { try { bhdResourceRating d = new bhdResourceRating(); d.resourceId = currentRating["resourceid"]; d.rating = currentRating["ratingscore"]; d.userId = currentRating["userid"]; dc.bhdResourceRatings.InsertOnSubmit(d); dc.SubmitChanges(); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.OK, ex); } } } } return response; }
public async Task<HttpResponseMessage> Post() { var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); // serialize that shit AuthorData uploadModel; try { uploadModel = JsonConvert.DeserializeObject<AuthorData>(jsonstring); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } List<GenDropList> repsonse = new List<GenDropList>(); try { using (ResourcesDataContext dc = new ResourcesDataContext()) { bhdAuthor newAuth = new bhdAuthor(); newAuth.name = uploadModel.AuthorName; newAuth.surname = uploadModel.AuthorSurname; newAuth.isActive = true; dc.bhdAuthors.InsertOnSubmit(newAuth); dc.SubmitChanges(); repsonse = (from d in dc.bhdAuthors where d.isActive == true select new GenDropList() { ListId = d.id, ListValue = d.name + " " + d.surname }).ToList(); } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. " + ex.Message + ". 400-3"); } return Request.CreateResponse(HttpStatusCode.OK, repsonse); }
public async Task<HttpResponseMessage> Post() { var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); // serialize that shit FileInfoData uploadModel; try { uploadModel = JsonConvert.DeserializeObject<FileInfoData>(jsonstring); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } try { using (ResourcesDataContext dc = new ResourcesDataContext()) { if (uploadModel.publisherid != 0 && uploadModel.authorid != 0) { bhdPublishInformation pubData = new bhdPublishInformation(); pubData.resourceId = uploadModel.resourceid; pubData.authorId = uploadModel.authorid; pubData.fileId = uploadModel.fileid; pubData.isActive = true; pubData.publisherId = uploadModel.publisherid; pubData.publishYear = uploadModel.publishYear; dc.bhdPublishInformations.InsertOnSubmit(pubData); dc.SubmitChanges(); } } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. " + ex.Message + ". 400-3"); } return Request.CreateResponse(HttpStatusCode.OK, "Sucess"); }
public async Task<HttpResponseMessage> Put(int id) { try { Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); List<ResourceBundle> newBundles = JsonConvert.DeserializeObject<List<ResourceBundle>>(jsonstring); using (ResourcesDataContext dc = new ResourcesDataContext()) { bhdResourceBundle currentBundle = dc.bhdResourceBundles.Single((x) => x.bundleId == id); List<bhdResourceBundleFile> bundleFiles = dc.bhdResourceBundleFiles.Where((x) => x.bundleId == id).ToList(); if ((newBundles.Count() == 0 && id != 0) || (currentBundle.isActive != newBundles.First().isActive)) { currentBundle.isActive = false; dc.SubmitChanges(); return Request.CreateResponse(HttpStatusCode.OK, string.Format("Bundle {0} successfully removed.", currentBundle.name)); } else if (newBundles.Count() > 0 && id != 0) { foreach (ResourceBundle rb in newBundles) { if (!bundleFiles.Any((x) => x.resourceFileId == rb.fileId)) { bhdResourceBundleFile newFile = new bhdResourceBundleFile(); newFile.resourceFileId = rb.fileId; newFile.bundleId = id; newFile.isFavourite = rb.isFavourite; dc.bhdResourceBundleFiles.InsertOnSubmit(newFile); dc.SubmitChanges(); } else { bhdResourceBundleFile currentfile = bundleFiles.Single((x) => x.resourceFileId == rb.fileId); currentfile.resourceFileId = rb.fileId; currentfile.bundleId = rb.bundleId; currentfile.isFavourite = rb.isFavourite; dc.SubmitChanges(); } } bundleFiles = dc.bhdResourceBundleFiles.Where((x) => x.bundleId == id).ToList(); foreach (bhdResourceBundleFile bf in bundleFiles) { if (!newBundles.Any((x) => x.fileId == bf.resourceFileId)) { dc.bhdResourceBundleFiles.DeleteOnSubmit(bf); dc.SubmitChanges(); } } } return Request.CreateResponse(HttpStatusCode.OK, string.Format("Bundle files sucessfully for {0}", currentBundle.name)); } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. " + ex.Message + ". 400-3"); } }
public async Task<HttpResponseMessage> Put(int id) { var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); ResourceList currentResource; try { currentResource = JsonConvert.DeserializeObject<ResourceList>(jsonstring); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } try { using (ResourcesDataContext db = new ResourcesDataContext()) { bhdResource approvalResource = db.bhdResources.Single((x) => x.id == currentResource.ResourceId); approvalResource.isActive = currentResource.isActive; approvalResource.approvalDate = DateTime.Now; approvalResource.approvalUser = id; db.SubmitChanges(); } if (currentResource.isActive) return Request.CreateResponse(HttpStatusCode.OK, "Resource approved!"); else return Request.CreateResponse(HttpStatusCode.OK, "Resource declined."); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } }
public void Delete(int id) { //this is where we deactivate resources using (ResourcesDataContext dc = new ResourcesDataContext()) { var r = (from d in dc.bhdResources join l in dc.bhdResourceLanguages on d.languageId equals l.id join top in dc.bhdResourceTopics on d.topicId equals top.id join typ in dc.bhdResourceTypes on d.typeId equals typ.id where d.id == id select d).FirstOrDefault(); if (r != null) { r.isActive = false; dc.SubmitChanges(); } } }
public async Task<HttpResponseMessage> Post(int id) { try { var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); var temp = JsonConvert.DeserializeObject<TagsInfo>(jsonstring); using (ResourcesDataContext dc = new ResourcesDataContext()) { foreach (var item in temp.tags) { var r = (from d in dc.bhdKeywords where d.isActive && d.value == item select d).FirstOrDefault(); if (r != null) { bhdResourceKeyword tmpResourceKeyword = new bhdResourceKeyword(); tmpResourceKeyword.KeywordId = r.id; tmpResourceKeyword.Resourceid = temp.ResourceId; dc.bhdResourceKeywords.InsertOnSubmit(tmpResourceKeyword); dc.SubmitChanges(); } else { bhdKeyword tmpkeyword = new bhdKeyword(); tmpkeyword.value = item; tmpkeyword.isActive = true; dc.bhdKeywords.InsertOnSubmit(tmpkeyword); dc.SubmitChanges(); bhdResourceKeyword tmpResourceKeyword = new bhdResourceKeyword(); tmpResourceKeyword.KeywordId = tmpkeyword.id; tmpResourceKeyword.Resourceid = temp.ResourceId; dc.bhdResourceKeywords.InsertOnSubmit(tmpResourceKeyword); dc.SubmitChanges(); } } } return Request.CreateResponse(HttpStatusCode.OK, "Success"); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. 400-1"); } }
public async Task<HttpResponseMessage> Post(int id, string type) { if (type != "website") { try { var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); ResourceFile resFileRet; var temp = JsonConvert.DeserializeObject<FileData>(jsonstring); using (ResourcesDataContext dc = new ResourcesDataContext()) { //check if we have the file type int typeid = 0; var temptype = (from d in dc.bhdFileTypes where d.contentType == temp.fileType && d.isActive select d).FirstOrDefault(); if (temptype == null) { bhdFileType ft = new bhdFileType(); ft.contentType = temp.fileType; string extension = temp.fileName; int pos = extension.LastIndexOf('.'); ft.extension = extension.Substring(pos + 1, extension.Length - (pos + 1)); ft.isActive = true; dc.bhdFileTypes.InsertOnSubmit(ft); dc.SubmitChanges(); typeid = ft.id; } else { typeid = temptype.id; } bhdFile f = new bhdFile(); f.size = temp.fileSize; f.name = temp.fileName; f.isActive = true; f.fileTypeId = typeid; dc.bhdFiles.InsertOnSubmit(f); dc.SubmitChanges(); bhdFileData fd = new bhdFileData(); fd.fileId = f.id; fd.data = temp.fileData; dc.bhdFileDatas.InsertOnSubmit(fd); dc.SubmitChanges(); bhdResource res = (from d in dc.bhdResources where d.id == id select d).FirstOrDefault(); res.previewFileId = f.id; dc.SubmitChanges(); } return Request.CreateResponse(HttpStatusCode.OK, "success"); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. 400-1"); } } else { try { //this is for a website string websiteUrl = ""; var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); var temp = JsonConvert.DeserializeObject<string>(jsonstring); websiteUrl = temp; using (ResourcesDataContext dc = new ResourcesDataContext()) { bhdLink l = new bhdLink(); l.url = websiteUrl; dc.bhdLinks.InsertOnSubmit(l); dc.SubmitChanges(); bhdResourceLink rl = new bhdResourceLink(); rl.linkId = l.linkId; rl.resourceId = id; dc.bhdResourceLinks.InsertOnSubmit(rl); dc.SubmitChanges(); } return Request.CreateResponse(HttpStatusCode.OK, "Success"); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. 400-9"); throw; } } }
public HttpResponseMessage Delete(int id) { HttpResponseMessage response = new HttpResponseMessage(); using (ResourcesDataContext db = new ResourcesDataContext()) { try { db.bhdResourceTopics.DeleteOnSubmit(db.bhdResourceTopics.Single((x) => x.id == id)); db.SubmitChanges(); } catch (Exception ex) { Request.CreateResponse(HttpStatusCode.PreconditionFailed, "Could not Remove the Topic. \r\n" + ex.ToString()); } } return response; }
public async Task<HttpResponseMessage> Post(int id) { try { var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); // serialize that shit ResourceEditSend uploadModel; try { uploadModel = JsonConvert.DeserializeObject<ResourceEditSend>(jsonstring); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } //update the information using (ResourcesDataContext dc = new ResourcesDataContext()) { bhdResource tmpResource = dc.bhdResources.Single((x) => x.id == id); tmpResource.name = uploadModel.resourceInfo.ResourceName; tmpResource.description = uploadModel.resourceInfo.ResourceDescription; tmpResource.topicId = uploadModel.resourceInfo.ResourceTopicId; tmpResource.languageId = uploadModel.resourceInfo.ResourceLanguageId; dc.SubmitChanges(); if (uploadModel.URL != "") { } dc.bhdResourceKeywords.DeleteAllOnSubmit<bhdResourceKeyword>(dc.bhdResourceKeywords.Where((r)=>r.Resourceid == id)); foreach (var item in uploadModel.tagsInfo.tags) { var r = (from d in dc.bhdKeywords where d.isActive && d.value == item select d).FirstOrDefault(); if (r != null) { bhdResourceKeyword tmpResourceKeyword = new bhdResourceKeyword(); tmpResourceKeyword.KeywordId = r.id; tmpResourceKeyword.Resourceid = tmpResource.id; dc.bhdResourceKeywords.InsertOnSubmit(tmpResourceKeyword); dc.SubmitChanges(); } else { bhdKeyword tmpkeyword = new bhdKeyword(); tmpkeyword.value = item; tmpkeyword.isActive = true; dc.bhdKeywords.InsertOnSubmit(tmpkeyword); dc.SubmitChanges(); bhdResourceKeyword tmpResourceKeyword = new bhdResourceKeyword(); tmpResourceKeyword.KeywordId = tmpkeyword.id; tmpResourceKeyword.Resourceid = tmpResource.id; dc.bhdResourceKeywords.InsertOnSubmit(tmpResourceKeyword); dc.SubmitChanges(); } } } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Something Broke. " + ex.Message + ". 400-3"); } return Request.CreateResponse(HttpStatusCode.OK, "Success"); }
public HttpResponseMessage Delete(int id) { using (ResourcesDataContext db = new ResourcesDataContext()) { db.bhdResourceComments.DeleteOnSubmit(db.bhdResourceComments.Single(x=>x.commentId == id)); db.SubmitChanges(); return Request.CreateResponse(HttpStatusCode.OK); } }
public async Task<HttpResponseMessage> Put() { HttpResponseMessage response = new HttpResponseMessage(); var result = Request.Content.ReadAsFormDataAsync(); Stream streamIn = await Request.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(streamIn); string jsonstring = streamReader.ReadToEnd(); Comment currentComment; try { currentComment = JsonConvert.DeserializeObject<Comment>(jsonstring); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } using (ResourcesDataContext db = new ResourcesDataContext()) { if (currentComment.commentId != 0) { bhdResourceComment editComment = db.bhdResourceComments.Single((x) => x.commentId == currentComment.commentId); editComment.commentDate = currentComment.commentDate; editComment.comment = currentComment.comment; editComment.isActive = currentComment.active; db.SubmitChanges(); response = Request.CreateResponse(HttpStatusCode.OK, "Comment sucessfully edited."); } else { bhdResourceComment newComment = new bhdResourceComment(); newComment.comment = currentComment.comment; newComment.commentDate = DateTime.Now; newComment.isActive = true; newComment.userId = currentComment.userId; newComment.resourceId = currentComment.resourceId; db.bhdResourceComments.InsertOnSubmit(newComment); db.SubmitChanges(); response = Request.CreateResponse(HttpStatusCode.OK, "New Format sucessfully added."); } } return response; }
public void Delete(int id) { using (ResourcesDataContext dc = new ResourcesDataContext()) { bhdResource currentResource = dc.bhdResources.Single((x) => x.id == id); currentResource.isActive = false; dc.SubmitChanges(); } }
public void Delete(int id, int fileid) { using (ResourcesDataContext dc = new ResourcesDataContext()) { var rb = dc.bhdResourceBundleFiles.Single((x) => x.bundleId == id && x.resourceFileId == fileid); if (rb != null) { dc.bhdResourceBundleFiles.DeleteOnSubmit(rb); dc.SubmitChanges(); } } }
public void Delete(int id) { using (ResourcesDataContext dc = new ResourcesDataContext()) { var rb = dc.bhdResourceBundles.Single((x) => x.bundleId == id); if (rb != null) { rb.isActive = false; dc.SubmitChanges(); } } }