public ActionResult Profile(string userName) { var context = new CrafterContext(); if (string.IsNullOrEmpty(userName)) { userName = User.Identity.Name; } var user = context.Users.Include(u => u.Tutorials).FirstOrDefault(u => u.UserName == userName); var userVm = new UserViewModel(user); return this.View(userVm); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Database.SetInitializer<CrafterContext>( new MigrateDatabaseToLatestVersion<CrafterContext, Configuration>()); var db = new CrafterContext(); db.Database.Initialize(true); }
public ActionResult GetUsers([DataSourceRequest]DataSourceRequest request) { var context = new CrafterContext(); var data = context.Users; var users = data.AsQueryable(); string query = Request.Params["query"]; if (query != null) { users = data.Where(u => u.UserName.ToLower().Contains(query.ToLower())); } var models = users.Select(TeamCentaur_LiveChat.ViewModels.SimpleUserViewModel.FromUser); DataSourceResult result = models.ToDataSourceResult(request); return Json(result); }
public ActionResult GetMyAvatar() { CrafterContext context = new CrafterContext(); var user = context.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); var avatar = user != null ? user.ImageUrl : null; ViewBag.Avatar = avatar; return PartialView("_GetAvatar"); }
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments) { System.Diagnostics.Trace.WriteLine("SavinG FiLe HeRe"); // The Name of the Upload component is "attachments" string imageLocation = string.Empty; foreach (var file in attachments) { // Some browsers send file names with full path. We only care about the file name. var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/Uploaded_Files"), fileName); imageLocation = "/Uploaded_Files/" + fileName; file.SaveAs(destinationPath); } var context = new CrafterContext(); var user = context.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); user.ImageUrl = imageLocation; context.SaveChanges(); // Return an empty string to signify success return Content(""); }
public AdminController() { this.db = new CrafterContext(); }