public async Task <IActionResult> AddArticle(Article article) { _context.Article.Add(article); _context.SaveChanges(); await Task.CompletedTask; return(new OkObjectResult(true)); }
public async Task <IActionResult> AddPost(Post post) { post.CommentCount = 0; _context.Posts.Add(post); _context.SaveChanges(); await Task.CompletedTask; return(new OkObjectResult(true)); }
public async Task <int> AddAlbum(Album album) { _context.Album.Add(album); _context.SaveChanges(); await Task.CompletedTask; var albumfromDB = _context.Album.Max(i => i.ID); _context.SaveChanges(); await Task.CompletedTask; return(albumfromDB); }
public async Task <IActionResult> GetFile([FromBody] UploadedImg img, int id) { // Create unique file name string photoId = Guid.NewGuid().ToString(); //string filePath = @"ClientApp\src\assets\Post\" + photoId + ".jpg"; string filePathDetail = "Photo/" + photoId + ".jpg"; string filePath = @"wwwroot\Photo\" + photoId + ".jpg"; // Remove file type from base64 encoding, if any if (img.FileAsBase64.Contains(",")) { img.FileAsBase64 = img.FileAsBase64 .Substring(img.FileAsBase64.IndexOf(",") + 1); } // Convert base64 encoded string to binary img.FileAsByteArray = Convert.FromBase64String(img.FileAsBase64); // Write binary file to server path using (var fs = new FileStream(filePath, FileMode.CreateNew)) { fs.Write(img.FileAsByteArray, 0, img.FileAsByteArray.Length); } ImgPath imgPath = new ImgPath(); imgPath.Path = filePathDetail; imgPath.AlbumID = id; _context.ImgPaths.Add(imgPath); _context.SaveChanges(); await Task.CompletedTask; return(new OkObjectResult(filePathDetail)); }
public ActionResult Register(user2 e) { DBCTX DC = new DBCTX(); DC.user.Add(e); DC.SaveChanges(); return(RedirectToAction("login")); }
public ActionResult Create(TABLE2 e) { using (dc) { dc.STOCK.Add(e); dc.SaveChanges(); } return(RedirectToAction("List")); }
public ActionResult Create(MAINPOPU e) { using (dc) { dc.MAINPOPU.Add(e); dc.SaveChanges(); } return(RedirectToAction("List")); }
public IActionResult GetFile([FromBody] UploadedImg img, int id) { // Create unique file name string photoId = Guid.NewGuid().ToString(); //string filePath = @"ClientApp\src\assets\Post\" + photoId + ".jpg"; string filePath = @"wwwroot\Photo\" + photoId + ".jpg"; // Remove file type from base64 encoding, if any if (img.FileAsBase64.Contains(",")) { img.FileAsBase64 = img.FileAsBase64 .Substring(img.FileAsBase64.IndexOf(",") + 1); } // Convert base64 encoded string to binary img.FileAsByteArray = Convert.FromBase64String(img.FileAsBase64); // Write binary file to server path using (var fs = new FileStream(filePath, FileMode.CreateNew)) { fs.Write(img.FileAsByteArray, 0, img.FileAsByteArray.Length); } var entity = _context.Album.FirstOrDefault(s => s.ID == id); if (entity == null) { return(new BadRequestResult()); } ImgPath path = new ImgPath(); path.Path = filePath; entity.ImgPaths.Add(path); _context.Entry(entity).CurrentValues.SetValues(entity); _context.SaveChanges(); return(new OkObjectResult("Photo/" + photoId + ".jpg")); }
public async Task <IActionResult> Register(UserModel user) { var query = _context.Users.FirstOrDefault(login => login.Username == user.Username); await Task.CompletedTask; if (query != null) { if (user.Username == query.Username) { return(new OkObjectResult(false)); } } user.Password = SecurePasswordHasher.Hash(user.Password); _context.Users.Add(user); _context.SaveChanges(); return(new OkObjectResult(true)); }