private bool IsValidItem(string type, string url) { bool valid = false; if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(url)) { switch (type.ToLower()) { case "upload": Upload.Models.Upload foundUpload = _dbContext.Uploads.Where(u => u.Url == url).FirstOrDefault(); if (foundUpload != null) { valid = true; } break; case "paste": Paste.Models.Paste foundPaste = _dbContext.Pastes.Where(p => p.Url == url).FirstOrDefault(); if (foundPaste != null) { valid = true; } break; } } return(valid); }
public IActionResult Paste(PasteAPIv1Model model) { try { if (model != null && model.code != null) { Paste.Models.Paste paste = PasteHelper.CreatePaste(_config, _dbContext, model.code, model.title, model.syntax, model.expireUnit, model.expireLength, model.password); // Associate this with the user if they are logged in if (User.Identity.IsAuthenticated) { User foundUser = UserHelper.GetUser(_dbContext, User.Identity.Name); if (foundUser != null) { paste.UserId = foundUser.UserId; } } _dbContext.Pastes.Add(paste); _dbContext.SaveChanges(); return(Json(new { result = new { id = paste.Url, url = Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url, password = model.password }), title = paste.Title, syntax = paste.Syntax, expiration = paste.ExpireDate, password = model.password } })); } return(Json(new { error = new { message = "Invalid Paste Request" } })); } catch (Exception ex) { return(Json(new { error = new { message = "Exception: " + ex.Message } })); } }