//[ValidateAntiForgeryToken] public async Task <IActionResult> Create(Dictionary <string, string> t) { string temp; t.TryGetValue("Text", out temp); Message message = new WebApplication1.Models.Message(temp, GlobalVariables.CurrentUser); try { _context.Messages.Add(message); await _context.SaveChangesAsync(); //GlobalVariables.Messages.Add(message); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } //ATTENTION! the place to redirect might change. //we'll need to redirect the user into the chatroom page //later: redirect to update + update function return(RedirectToAction("index", "message", "api/message/index/")); }
public IActionResult Send([FromBody] //dynamic input Dictionary <string, string> t ) { //var client = new HttpClient(); ////client.BaseAddress = new Uri("http://localhost:1302/api/"); //client.BaseAddress = new Uri("applicationUrl"); //client.DefaultRequestHeaders.Accept.Clear(); //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //return RedirectToAction("Android", "message", "api/Message/Android"); //JToken token = JObject.Parse(input); string user, text; //return Json(_context.Messages.ToList()); t.TryGetValue("Username", out user); t.TryGetValue("Text", out text); //user = (string)token.SelectToken("Username"); //text = (string)token.SelectToken("Text"); //return Ok(user); Message message = new WebApplication1.Models.Message(text, user); _context.Messages.Add(message); _context.SaveChanges(); // PAKEISTI (veliau)???? return(RedirectToAction("Android", "message", "api/message/Android")); }
public JsonResult AddMessageToDB(string[] data) { Message mess = new Message(); mess.Name = data[0]; mess.Email = data[1]; mess.Text = data[2]; var context = new SushiTest1Entities1(); context.Messages.Add(mess); context.SaveChanges(); return Json(new { res = "good" }); }
public ActionResult Contact(Message msg) { MailHelper mailer = new MailHelper(); string response = mailer.EmailFromArvixe( new Message(msg.Sender, msg.Subject, msg.Body)); if (response == "FAIL TO SEND MAIL") { ViewBag.Response = response; return View(); } else { return RedirectToAction("Success", new { message = response }); } }
// GET: Home public ActionResult Index() { Model1 contex=new Model1(); Message d=new Message() { MessageId = 1, Date = DateTime.Now, Text = "wef", UserFrom = new User(), UserTo = new User() }; contex.Messages.Add(d); return View(); }