public IHttpActionResult GetAllContacts(contactus contact) { try { //checking model propety if (ModelState.IsValid) { using (var ctx = new MayowaaEntities()) { ctx.messages.Add(new message { userName = contact.userName, emailAddress = contact.emailAddress, phoneNumber = contact.phoneNumber, message1 = contact.message }); ctx.SaveChanges(); } return(Ok(HttpStatusCode.Created)); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { throw ex.InnerException; } }
public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("Not a valid user id")); } using (var ctx = new MayowaaEntities()) { var message = ctx.messages.Where(s => s.id == id).FirstOrDefault(); ctx.Entry(message).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } return(Ok("deleted message successfully")); }
public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("Not a valid user id")); } using (var ctx = new MayowaaEntities()) { var signupdata4 = ctx.SignUps.Where(s => s.id == id).FirstOrDefault(); ctx.Entry(signupdata4).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } return(Json(new response { State = stateparameters.success, Msg = "deleted successfully" })); //return Ok ("deleted successfully"); }
public IHttpActionResult GetAllSignup(signupData signupData) // name of the model + ...\ { try { if (signupData.passWord == signupData.confirmPassword) { if (ModelState.IsValid) { using (var ctx = new MayowaaEntities()) { ctx.SignUps.Add(new SignUp { emailAddress = signupData.emailAddress, firstName = signupData.firstName, lastName = signupData.lastName, passWord = signupData.passWord }); ctx.SaveChanges(); } return(Json(new response { State = stateparameters.success, Msg = "Successful", })); } else { return(Json(new response { State = stateparameters.failed, Msg = "Invalid credentials", Data = ModelState })); } } else { return(Ok("Passwords do not match")); } } catch (Exception ex) { throw ex.InnerException; } }
public IHttpActionResult Put(int id, signupData signupData) { if (ModelState.IsValid) { try { using (var ctx = new MayowaaEntities()) { var existingusers = ctx.SignUps.Where(s => s.id == id).FirstOrDefault <SignUp>(); if (existingusers != null) { existingusers.firstName = signupData.firstName; existingusers.lastName = signupData.lastName; existingusers.emailAddress = signupData.emailAddress; existingusers.passWord = signupData.passWord; ctx.SaveChanges(); return(Json(new response { State = stateparameters.success, Data = existingusers })); } else { return(Json(new response { State = stateparameters.failed, Msg = "Invalid Credentials" })); } } } catch (Exception) { throw; } } else { return(Ok("Not a valid model")); } }