public async Task <IActionResult> PutMssg(int id, Mssg mssg) { if (id != mssg.MssgId) { return(BadRequest()); } _context.Entry(mssg).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MssgExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/*public async Task<ActionResult<Mssg>> PostMssg(Mssg mssg) * { * * _context.Mssg.Add(mssg); * await _context.SaveChangesAsync(); * return mssg; * }*/ public async Task <Mssg> PostMssg(Mssg mssg) { Contacts oldContact = _context.Contacts.Where(contact => contact.ContactsEmail == mssg.MssgEmail && contact.ContactsTel == mssg.MssgTel).FirstOrDefault(); if (oldContact == null) { Contacts contact = new Contacts(); contact.ContactsName = mssg.MssgName; contact.ContactsEmail = mssg.MssgEmail; contact.ContactsTel = mssg.MssgTel; _context.Contacts.Add(contact); await _context.SaveChangesAsync(); Contacts newContact = _context.Contacts.Where(cont => cont.ContactsEmail == contact.ContactsEmail && cont.ContactsTel == contact.ContactsTel).FirstOrDefault(); mssg.MssgContact = newContact.ContaccsId; } else { mssg.MssgContact = oldContact.ContaccsId; } _context.Mssg.Add(mssg); await _context.SaveChangesAsync(); var record = _context.Mssg.Where(messg => messg.MssgId == mssg.MssgId).FirstOrDefault(); return(record); }
public ActionResult SendMsg(Mssg log) { //for adding new record to the databse taht user added in the text boxes Connection obj = new Connection(); String query = "insert into contact(Sname,Scontact,Semail,Smsg) values('" + log.SName + "','" + log.SPhone + "','" + log.SEmail + "','" + log.SMsg + "')"; obj.InsDelUpdt(query); return(View("reveiws")); }