public async Task <ActionResult <ArticleMaster> > PostArticleMaster(ArticleMaster articleMaster) { _context.Article_Masters.Add(articleMaster); await _context.SaveChangesAsync(); return(CreatedAtAction("GetArticleMaster", new { id = articleMaster.id }, articleMaster)); }
public async Task <IActionResult> PutArticleMaster(int id, ArticleMaster articleMaster) { if (id != articleMaster.id) { return(BadRequest()); } _context.Entry(articleMaster).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleMasterExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// GET: ProductMasterController/Edit/5 public ActionResult Edit(ArticleMaster article) { string query = @"Update ProductMaster set Article_Title ='" + article.ArticleTitle + "', " + "Category_Id = '" + article.CategoryId + "Section_Id = '" + article.SectionId + "User_Id = '" + article.Id + "Reviewer_Id = '" + article.ReviewerId + "Product_Id = '" + article.ProductId + "Description = '" + article.Article_Description + "Visibility = '" + article.Visible + "Status = '" + article.status + "CommentAllow = '" + article.CommentAllow + "UseFullTotal = '" + article.UseFullTotal + "UseFullCount = '" + article.UseFullCount + "Draft = '" + article.Draft + "Archive = '" + article.Archive + "' where Article_Id = " + article.ArticleId; DataTable table = new DataTable(); string sqlDataSource = configuration.GetConnectionString("DataConnection"); SqlDataReader dataReader; using (SqlConnection connection = new SqlConnection(sqlDataSource)) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { dataReader = command.ExecuteReader(); table.Load(dataReader); dataReader.Close(); connection.Close(); } } return(new JsonResult("Data Updated")); }
public string GetUploadArticle([FromBody] ArticleMaster newArticle) { //Create hash , return as url using (MD5 md5Hash = MD5.Create()) { newArticle.url = GetMd5Hash(md5Hash, (newArticle.text + newArticle.title + newArticle.author_id.ToString())); newArticle.uploaded_date = DateTime.Now; //Upload to db try { dc.ArticleMasters.InsertOnSubmit(newArticle); dc.SubmitChanges(); newArticle = (from x in dc.GetTable <ArticleMaster>() where x == newArticle select x).Single(); } catch (Exception e) { return(newArticle.url); //Same author , title and body {text} then consider duplicate } newArticle.url = GetMd5Hash(md5Hash, newArticle.Id.ToString()); dc.SubmitChanges(); } return(newArticle.url); }
public JsonResult Create(ArticleMaster article) { try { string query = @"insert into ArticleMaster (Article_Title,Category_Id,Section_Id,User_Id,Reviewer_Id,Product_Id,Description,Visibility,Status,CommentAllow,UseFullTotal,UseFullCount,Draft,Archive) values ('" + article.ArticleTitle + "','" + article.CategoryId + "','" + article.SectionId + "','" + article.Id + "','" + article.ReviewerId + "','" + article.ProductId + "','" + article.Article_Description + "','" + article.Visible + "','" + article.status + "','" + article.CommentAllow + "','" + article.UseFullTotal + "','" + article.UseFullCount + "','" + article.Draft + "','" + article.Archive + "')"; DataTable table = new DataTable(); string sqlDataSource = configuration.GetConnectionString("DataConnection"); SqlDataReader dataReader; using (SqlConnection connection = new SqlConnection(sqlDataSource)) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { dataReader = command.ExecuteReader(); table.Load(dataReader); dataReader.Close(); connection.Close(); } } return(new JsonResult("Data Inserted")); } catch (Exception e) { return(new JsonResult(e.Message)); } }
public ArticleReturn GetArticle(string url) { ArticleMaster articles = (from x in dc.GetTable <ArticleMaster>() where x.url == url select x).SingleOrDefault(); AuthorMaster authorIs = (from auth in dc.GetTable <AuthorMaster>() where auth.Id == articles.author_id select auth).SingleOrDefault(); ArticleReturn ar = new ArticleReturn() { Id = articles.Id, author_id = articles.author_id, author_fname = authorIs.fname, author_lname = authorIs.lname, title = articles.title, uploaded_date = articles.uploaded_date, url = articles.url, author_uname = authorIs.uname, text = articles.text }; return(ar); }
public async Task <ActionResult <ArticleMaster> > PostArticleMaster2(string articlecode, string site, ArticleMaster articleMaster) { var article = _context.Article_Masters.Where(x => x.Article_Code == articlecode).Where(y => y.Site == site).Count(); if (article > 0) { return(Ok("Duplicate")); } _context.Article_Masters.Add(articleMaster); await _context.SaveChangesAsync(); return(CreatedAtAction("GetArticleMaster", new { id = articleMaster.id }, articleMaster)); }