public IHttpActionResult Message(UserSendMessModel data) { DAL.DataContext dt = new DAL.DataContext(); string current_user = User.Identity.GetUserId(); string send_user = data.Send; string content = data.Content; ChatSession cs; cs = dt.ChatSessions.Where(u => u.ReceiveID == current_user || u.SenderID == current_user).FirstOrDefault(); if (cs == null) { cs = new ChatSession(); cs.SenderID = current_user; cs.ReceiveID = send_user; dt.ChatSessions.Add(cs); dt.SaveChanges(); } User send = dt.Users.Where(u => u.Id == current_user).FirstOrDefault(); User receiver = dt.Users.Where(u => u.Id == send_user).FirstOrDefault(); Message mess = new Message(); mess.Sender = send; mess.Receive = receiver; mess.Content = content; mess.when = DateTime.Now; mess.ChatSession = cs; dt.Messages.Add(mess); dt.SaveChanges(); return(Ok()); }
public ActionResult Setting(Models.UserSettingViewModel model) { HttpPostedFileBase file = model.attachment; DAL.DataContext dt = new DAL.DataContext(); Models.User currentUser = dt.Users.Find(User.Identity.GetUserId()); currentUser.Email = model.Email; currentUser.FName = model.FName; currentUser.Quote = model.Quote; currentUser.LName = model.LName; if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Content/images/avatar_path"), pic); // file is uploaded file.SaveAs(path); string new_path = "/Content/images/avatar_path/" + pic; currentUser.AvatarPath = new_path; } model.AvatarPath = currentUser.AvatarPath; dt.SaveChanges(); return(View(model)); }
public ActionResult Employee(Employee employee) { DAL.DataContext db = new DAL.DataContext(); db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Search public ActionResult Index() { DAL.DataContext dt = new DAL.DataContext(); int lang_id = 0; string my_id = User.Identity.GetUserId(); dt.Configuration.LazyLoadingEnabled = false; List <Models.User> result = new List <Models.User>(); string type = Request.QueryString["type"]; string language = Request.QueryString["language"]; if (type != null && language != null) { lang_id = Int32.Parse(language); Languages lang = dt.Languages.Where(l => l.Id == lang_id).FirstOrDefault(); int mlanguage = Int32.Parse(language); IdentityRole rl = new IdentityRole(); rl = (type == "teacher" ? dt.Roles.Where(r => r.Name == "Teacher").FirstOrDefault() : dt.Roles.Where(r => r.Name == "Student").FirstOrDefault()); result = this.UserManager.Users.Where(u => u.SecondLang.Any(m => m.Language.Id == lang.Id)).Where(u => u.Roles.Any(r => r.RoleId == rl.Id)).Where(i => i.Id != my_id).ToList(); } ViewBag.Results = result; ViewBag.LangId = lang_id; ViewBag.Type = type; ViewBag.Languages = dt.Languages.ToList(); return(View()); }
// GET: Home public ActionResult Index() { DAL.DataContext dt = new DAL.DataContext(); dt.Configuration.LazyLoadingEnabled = false; ViewBag.Courses = dt.Courses.Include("Teacher").Include("Language").OrderBy(r => Guid.NewGuid()).Take(4).ToList(); return(View()); }
public ActionResult ChangeStatus(TeacherChangeCourse cs) { DAL.DataContext dt = new DAL.DataContext(); CourseSession myCs = dt.CourseSessions.Where(c => c.Id == cs.SeId).FirstOrDefault(); myCs.Status = "Accepted"; dt.SaveChanges(); return(RedirectToAction("TeacherSchedule", "Account")); }
public T AddAsync(T entity) { using (var context = new DAL.DataContext()) { context.Entry(entity).State = EntityState.Added; context.SaveChanges(); } return(entity); }
public ActionResult MySchedule() { DAL.DataContext dt = new DAL.DataContext(); string current_id = User.Identity.GetUserId(); List <CourseSession> cs = dt.CourseSessions.Include("Teacher").Include("Student").Where(c => c.Student.Id == current_id).ToList(); ViewBag.Courses = cs; return(View()); }
public ActionResult ListCourses() { DAL.DataContext dt = new DAL.DataContext(); dt.Configuration.LazyLoadingEnabled = false; string current_id = User.Identity.GetUserId(); List <Course> cs = dt.Courses.Where(c => c.Teacher.Id == current_id).ToList(); ViewBag.Course = cs; return(View()); }
public ActionResult SaveBalance(BalanceViewModel ba) { DAL.DataContext dt = new DAL.DataContext(); User current = dt.Users.Find(User.Identity.GetUserId()); int balance = current.Balance; balance += ba.Amount; current.Balance = balance; dt.SaveChanges(); return(RedirectToAction("Balance", "Account")); }
public Dictionary <int, string> Courses(string id) { DAL.DataContext dt = new DAL.DataContext(); Dictionary <int, string> result = new Dictionary <int, string>(); foreach (var c in dt.Courses.Where(c => c.Teacher.Id == id)) { result.Add(c.Id, c.Title); } return(result); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: using (var context = new DAL.DataContext()) { var userData = context.Users.FirstOrDefault(x => x.Email == model.Email); //Todo find current game if (userData != null) { var userModel = new UserGameModel { UserId = userData.UserId, TimeZone = "SE Asia Standard Time", Email = model.Email }; } var serializer = new JavaScriptSerializer(); var cookie = new HttpCookie("User", serializer.Serialize(userData)) { Expires = DateTime.Now.AddYears(1) }; Response.Cookies.Add(cookie); } return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public ActionResult Balance() { DAL.DataContext dt = new DAL.DataContext(); User current = dt.Users.Find(User.Identity.GetUserId()); BalanceViewModel ba = new BalanceViewModel() { Amount = current.Balance }; return(View(ba)); }
public ActionResult Teacher() { DAL.DataContext dt = new DAL.DataContext(); List <Models.User> result; IdentityRole rl = new IdentityRole(); rl = dt.Roles.Where(r => r.Name == "Teacher").FirstOrDefault(); result = dt.Users.Where(u => u.Roles.Any(r => r.RoleId == rl.Id)).ToList(); ViewBag.Students = result; return(View()); }
public static List <Course> Course() { DAL.DataContext dt = new DAL.DataContext(); List <Course> courses = new List <Course> { new Course { Language = dt.Languages.Find(1), Title = "IELTS Focus", Cost = 100 } }; return(courses); }
public ActionResult Language() { DAL.DataContext dt = new DAL.DataContext(); string my_id = User.Identity.GetUserId(); dt.Configuration.LazyLoadingEnabled = false; List <Models.LanguageSkill> langs; langs = dt.SecondLanguages.Include("Language").Where(u => u.User.Id == my_id).ToList(); var filter = dt.SecondLanguages.Select(l => l.Language.Id).ToList(); List <Models.Languages> allLangs = dt.Languages.Where(f => !filter.Contains(f.Id)).ToList(); ViewBag.AllLangs = allLangs; ViewBag.Langs = langs; return(View()); }
public static List <User> Teachers() { DAL.DataContext dt = new DAL.DataContext(); List <User> teachers = new List <User> { new User { FName = "Chris", LName = "Cook", UserName = "******", Email = "*****@*****.**", AvatarPath = "/images/user_avatar/chris22.jpg", NativeLang = dt.Languages.Find(1), Balance = 0, Country = "Canada" }, new User { FName = "Mike", LName = "Warren", UserName = "******", Email = "*****@*****.**", AvatarPath = "/images/user_avatar/mike22.jpg", NativeLang = dt.Languages.Find(2), Balance = 0, Country = "Canada" }, new User { FName = "Florencia", LName = "Ferreira", UserName = "******", Email = "*****@*****.**", AvatarPath = "/images/user_avatar/floren22.jpg", NativeLang = dt.Languages.Find(3), Balance = 0, Country = "Canada" }, new User { FName = "Sophie", LName = "Horrocks", UserName = "******", Email = "*****@*****.**", AvatarPath = "/images/user_avatar/sophie.jpg", NativeLang = dt.Languages.Find(3), Balance = 0, Country = "Canada" } }; /*foreach (User te in teachers) { * * te.Ad * * * dt.Users.Add(te); * * for (int i = 0; i <= 5; i++) * { * * * int r = rnd.Next(courseName.Count); * int rCost = rnd.Next(costs.Count); * Course course = new Course { Description="",Language = dt.Languages.Find(1), Title = courseName[rnd.Next(courseName.Count)], Cost = costs[rnd.Next(costs.Count)] }; * course.Teacher = te; * dt.Courses.Add(course); * * } * * * * }*/ //dt.SaveChanges(); return(teachers); }
public ActionResult ChangeStatus(TeacherChangeCourse cs) { DAL.DataContext dt = new DAL.DataContext(); CourseSession myCss = dt.CourseSessions.Where(c => c.Id == cs.SeId).First(); int fee = myCss.Course.Cost; User teacher = myCss.Teacher; User stu = myCss.Student; myCss.Status = "Completed"; teacher.Balance = teacher.Balance + fee; stu.Balance = stu.Balance - fee; dt.SaveChanges(); return(RedirectToAction("MySchedule", "Account")); }
public ActionResult Setting() { DAL.DataContext dt = new DAL.DataContext(); Models.User currentUser = dt.Users.Find(User.Identity.GetUserId()); Models.UserSettingViewModel model = new Models.UserSettingViewModel() { AvatarPath = currentUser.AvatarPath, FName = currentUser.FName, LName = currentUser.LName, Quote = currentUser.Quote, Email = currentUser.Email }; ViewBag.User = currentUser; return(View(model)); }
public ActionResult SaveCourse(CourseViewModel cs) { DAL.DataContext dt = new DAL.DataContext(); Models.User currentUser = dt.Users.Find(User.Identity.GetUserId()); Course course = new Course(); course.Description = cs.Des; course.Title = cs.Title; course.Cost = cs.Cost; course.Language = dt.Languages.FirstOrDefault(); course.Teacher = currentUser; dt.Courses.Add(course); dt.SaveChanges(); return(RedirectToAction("ListCourses", "Account")); }
public ActionResult SaveLanguage() { DAL.DataContext dt = new DAL.DataContext(); int lang_id = Int32.Parse(Request.Form["lang"]); int level = Int32.Parse(Request.Form["level"]); LanguageSkill lang = new LanguageSkill(); lang.Language = dt.Languages.Where(l => l.Id == lang_id).FirstOrDefault(); string user_id = User.Identity.GetUserId(); lang.User = dt.Users.Where(u => u.Id == user_id).FirstOrDefault(); lang.Level = level; dt.SecondLanguages.Add(lang); dt.SaveChanges(); return(RedirectToAction("Language", "Account")); }
public IHttpActionResult SaveCourseSession(UserSaveCourse cs) { DAL.DataContext dt = new DAL.DataContext(); Course my_cs = dt.Courses.Include("Teacher").Where(c => c.Id == cs.CourseId).FirstOrDefault(); CourseSession css = new CourseSession(); css.Teacher = my_cs.Teacher; css.Course = my_cs; DateTime oDate = DateTime.ParseExact(cs.MyTime, "yyyy-MM-dd HH:mm", null); css.When = oDate; User current = dt.Users.Find(User.Identity.GetUserId()); css.Student = current; css.Status = "Waiting Accept"; dt.CourseSessions.Add(css); dt.SaveChanges(); return(Ok()); }
public ActionResult SaveChat(ChatBoxSend box) { int session_id = box.SessionId; string my_id = User.Identity.GetUserId(); DAL.DataContext dt = new DAL.DataContext(); ChatSession cs = dt.ChatSessions.Where(c => c.Id == session_id).FirstOrDefault(); string receiver_id = (cs.SenderID == my_id ? cs.ReceiveID : cs.SenderID); Message ms = new Message(); ms.SenderID = my_id; ms.ReceiveID = receiver_id; ms.Content = box.Content; ms.ChatSession = cs; ms.when = DateTime.Now; dt.Messages.Add(ms); dt.SaveChanges(); return(RedirectToAction("MailBox", "Account", new { id = session_id })); }
public async Task <ActionResult> Register(Models.StudentRegisterViewModel model) { if (ModelState.IsValid) { DAL.DataContext dt = new DAL.DataContext(); Models.User newUser = new Models.User { UserName = model.Email, FName = model.FName, LName = model.LName, Email = model.Email, NativeLang = dt.Languages.Find(4), Balance = 0, Country = "Canada" }; var result = await UserManager.CreateAsync(newUser, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(newUser, isPersistent : false, rememberBrowser : false); await UserManager.AddToRoleAsync(newUser.Id, "Student"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } return(View(model)); }
public ActionResult Mailbox(int id) { int session_id = id; DAL.DataContext dt = new DAL.DataContext(); dt.Configuration.LazyLoadingEnabled = false; User currentUser = dt.Users.Find(User.Identity.GetUserId()); List <ChatSession> cs = dt.ChatSessions.Include("Sender").Include("Receive").Where(c => c.ReceiveID == currentUser.Id || c.SenderID == currentUser.Id).ToList(); Models.UserSettingViewModel model = new Models.UserSettingViewModel() { Balance = currentUser.Balance, FName = currentUser.FName, LName = currentUser.LName, UserId = User.Identity.GetUserId(), ChatSessions = cs, }; List <Message> mymess = new List <Message>(); if (session_id == 0 && cs.Count > 0) { int cs_id = cs[0].Id; session_id = cs_id; mymess = dt.Messages.Where(c => c.ChatSession.Id == cs_id).ToList(); } else if (session_id != 0) { mymess = dt.Messages.Where(c => c.ChatSession.Id == session_id).ToList(); } ViewBag.MyMess = mymess; ViewBag.SessionId = session_id; return(View(model)); }
public ActionResult Index() { DAL.DataContext db = new DAL.DataContext(); ViewBag.employee = (from d in db.Employees select d).ToList(); return(View()); }
public FileService(DataContext context) { _context = context; }
public MaterialService(DataContext context) { _context = context; _fileService = new FileService(context); }