public ActionResult ChangePassword(string CurrentPassword, string NewPassword, string ConfirmPassword) { using (var context = new AppContextMain()) { User user = context.Users.Find(Convert.ToInt32(Session["UserId"].ToString())); if (user.Password != CurrentPassword.Trim()) { return Json(new { Success = false, Message = "The current password you have entered is incorrect.", Error = 0 }, JsonRequestBehavior.AllowGet); } else { if (user.Password == NewPassword.Trim()) { return Json(new { Success = false, Message = "New password must be different from current password.", Error = 1 }, JsonRequestBehavior.AllowGet); } else { user.Password = NewPassword.Trim(); user.DateUpdated = DateTime.Now; context.Entry(user).State = EntityState.Modified; context.SaveChanges(); Session.Clear(); Session.Abandon(); return Json(new { Success = true, Message = "Password Changed successfully." }, JsonRequestBehavior.AllowGet); } } } }
public ActionResult UpdateProfile(User user) { using (var context = new AppContextMain()) { int userId = Convert.ToInt32(Session["UserId"].ToString()); if (CheckIfUsernameExists(user.Username.Trim(), userId)) { return Json(new { Success = false, Message = "Username already exists." }, JsonRequestBehavior.AllowGet); } User temp = context.Users.Find(userId); if ((temp.FirstName != user.FirstName.ToLower()) || (temp.LastName != user.LastName.ToLower()) || (temp.Gender != user.Gender) || (temp.BirthDate != user.BirthDate) || (temp.Username != user.Username.Trim())) { temp.FirstName = user.FirstName.ToLower().Trim(); temp.LastName = user.LastName.ToLower().Trim(); temp.Gender = user.Gender; temp.BirthDate = user.BirthDate; temp.Username = user.Username.Trim(); temp.DateUpdated = DateTime.Now; context.Entry(temp).State = EntityState.Modified; context.SaveChanges(); return Json(new { Success = true, Message = "Profile updated successfully." }, JsonRequestBehavior.AllowGet); } else { return Json(new { Success = false }, JsonRequestBehavior.AllowGet); } } }
public IHttpActionResult Post() { SinchHeader sinchInbound = JsonConvert.DeserializeObject <SinchHeader>(PostRespo()); using (var appContextMain = new AppContextMain()) { if (sinchInbound.inbounds.Count != 0) { appContextMain.SinchPosts.Add(new SinchPost { SinchId = sinchInbound.inbounds[0].id, FromNumber = sinchInbound.inbounds[0].from, Content = sinchInbound.inbounds[0].body, MsgType = sinchInbound.inbounds[0].type, ReceivedDate = DateTime.Parse(sinchInbound.inbounds[0].received_at) }); appContextMain.SaveChanges(); ApiResponse apirespo = new ApiResponse(); apirespo = tryText(@"http://0499a5363700.ngrok.io/api/AgentSuite/HowAmITrending?AgentContactNumber=" + sinchInbound.inbounds[0].from + "^&Option=" + sinchInbound.inbounds[0].body); //apirespo = tryText(@"http://0499a5363700.ngrok.io/api/AgentSuite/HowAmITrending?AgentContactNumber=639173009761^&Option=A"); var smsMessage = GetResponse(sinchInbound.inbounds[0].from, apirespo.result + " " + apirespo.status); //var smsMessage = GetResponse("639173009761", "TRIAL"); return(Ok(new { Success = true })); //return Ok(new { Success = tryText(@"http://0499a5363700.ngrok.io/api/AgentSuite/HowAmITrending?AgentContactNumber=09173009761^&Option=G").status }); } } return(Ok(new { Success = false })); }
protected bool CheckIfUsernameExists(string username) { using (var context = new AppContextMain()) { return(context.Users.Where(u => u.Username == username).SingleOrDefault() != null); } }
protected bool CheckIfUsernameExists(string username, int id) { using (var context = new AppContextMain()) { return context.Users.Where(u => u.Username == username && u.UserId != id).SingleOrDefault() != null; } }
public bool CheckIfTitleExistsForEdit(string title, int todoId) { using (var context = new AppContextMain()) { int UserId = Convert.ToInt32(Session["UserId"].ToString()); return(context.Todos.Where(t => t.Title == title && t.UserReference == UserId && t.TodoId != todoId).SingleOrDefault() != null); } }
public void GetStudentById_Test() { using (var mainContext = new AppContextMain()) { var student = mainContext.Students.Where(x => x.Id == 6).FirstOrDefault(); Assert.AreEqual("test name", student.Name); } }
public void GetAllStudents_Test() { using (var mainContext = new AppContextMain()) { var studentList = mainContext.Students; Assert.AreEqual(10, studentList.Count()); } }
private static void GetStudentById() { using (var mainContext = new AppContextMain()) { var student = mainContext.Students.Where(x => x.Id == 7).FirstOrDefault(); Console.WriteLine("{0} - {1}", student.Id, student.Name); } }
public ActionResult Delete(int?id) { using (var context = new AppContextMain()) { Todo todo = context.Todos.Find(id); context.Todos.Remove(todo); context.SaveChanges(); } return(Json(new { Result = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult Index() { using (var context = new AppContextMain()) { int UserId = Convert.ToInt32(Session["UserId"].ToString()); //int UserId = 2; List <Todo> todos = context.Todos.Where(t => t.UserReference == UserId).OrderByDescending(t => t.DateCreated).ToList(); return(Json(todos, JsonRequestBehavior.AllowGet)); } }
public void DeleteStudentId_Test() { using (var mainContext = new AppContextMain()) { var student = mainContext.Students.FirstOrDefault(x => x.Id == 6); mainContext.Students.Remove(student); mainContext.SaveChanges(); Assert.Inconclusive("Student Deleted"); } }
public ActionResult ChangeIsDoneStatus(int?id) { using (var context = new AppContextMain()) { Todo todo = context.Todos.Find(id); todo.IsDone = todo.IsDone == 1 ? 0 : 1; context.Entry(todo).State = EntityState.Modified; context.SaveChanges(); } return(Json(new { Result = true }, JsonRequestBehavior.AllowGet)); }
private static void GetAllStudents() { using (var mainContext = new AppContextMain()) { var studentList = mainContext.Students; foreach (var student in studentList) { Console.WriteLine("{0} - {1}", student.Id, student.Name); } } }
public ActionResult Login(User user) { using (var context = new AppContextMain()) { var data = context.Users.Where(u => u.Username == user.Username && u.Password == user.Password).SingleOrDefault(); if (data != null) { Session["UserId"] = data.UserId; return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } }
public void SaveSinchPost_Test() { using (var mainContext = new AppContextMain()) { mainContext.SinchPosts.Add(new SinchPost { Content = "Marc Griffin" }); mainContext.SaveChanges(); } Assert.Inconclusive("Sinch Post Saved"); }
public void SaveStudent_Test() { using (var mainContext = new AppContextMain()) { mainContext.Students.Add(new Student { Name = "Marc Griffin", Status = "Active" }); mainContext.SaveChanges(); } Assert.Inconclusive("Student Saved"); }
private static void DeleteStudentId() { using (var mainContext = new AppContextMain()) { var student = mainContext.Students.FirstOrDefault(x => x.Id == 7); if (student != null) { mainContext.Students.Remove(student); mainContext.SaveChanges(); Console.WriteLine("Student Deleted"); } } }
private static void SaveStudent() { using (var mainContext = new AppContextMain()) { mainContext.Students.Add(new Student { Name = "Leng Ganda", Status = "Active" }); mainContext.SaveChanges(); } Console.WriteLine("Student Saved!"); }
public ActionResult ReadProfile() { using (var context = new AppContextMain()) { User user = context.Users.Find(Convert.ToInt32(Session["UserId"].ToString())); var data = new { Username = user.Username, FirstName = user.FirstName, LastName = user.LastName, Gender = user.Gender, BirthDate = user.BirthDate }; return Json(data, JsonRequestBehavior.AllowGet); } }
public ActionResult Register(User user) { if (CheckIfUsernameExists(user.Username)) { return(Json(new { Result = false, Message = "Username already exists." }, JsonRequestBehavior.AllowGet)); } user.FirstName = user.FirstName.ToLower(); user.LastName = user.LastName.ToLower(); user.DateCreated = DateTime.Now; user.DateUpdated = DateTime.Now; user.Username = user.Username.Trim(); user.Password = user.Password.Trim(); user.Status = 1; using (var context = new AppContextMain()) { context.Users.Add(user); context.SaveChanges(); } return(Json(new { Result = true, Message = "User Registration Successful." }, JsonRequestBehavior.AllowGet)); }
static void Main(string[] args) { Console.WriteLine(string.Format("Starting {0}", ConfigurationManager.AppSettings["AppName"])); using (var appContextMain = new AppContextMain()) { appContextMain.Students.Add(new Student { Id = 2, Name = "Angel Locsin", Status = "Active" }); appContextMain.SaveChanges(); } Console.WriteLine("Completed"); Console.ReadKey(); }
public ActionResult Create(Todo todo) { if (CheckIfTitleExistsForCreate(todo.Title)) { return(Json(new { Result = false, Message = "Title already exists." }, JsonRequestBehavior.AllowGet)); } using (var context = new AppContextMain()) { todo.Title = todo.Title.ToLower(); todo.Description = todo.Description.ToLower(); todo.UserReference = Convert.ToInt32(Session["UserId"]); todo.IsDone = 0; todo.Status = 1; todo.DateCreated = DateTime.Now; todo.DateUpdated = DateTime.Now; context.Todos.Add(todo); context.SaveChanges(); return(Json(new { Result = true }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit(Todo todo) { if (CheckIfTitleExistsForEdit(todo.Title, todo.TodoId)) { return(Json(new { Result = false, Message = "Title already exists." }, JsonRequestBehavior.AllowGet)); } using (var context = new AppContextMain()) { Todo temp = context.Todos.Find(todo.TodoId); if (temp.Title != todo.Title.ToLower() || temp.Description != todo.Description) { temp.Title = todo.Title.ToLower(); temp.Description = todo.Description; temp.DateUpdated = DateTime.Now; context.Entry(temp).State = EntityState.Modified; context.SaveChanges(); return(Json(new { Result = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { Result = false }, JsonRequestBehavior.AllowGet)); } }