コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: TeamCentaur/Crafter
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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");
 }
コード例 #5
0
        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("");
        }
コード例 #6
0
 public AdminController()
 {
     this.db = new CrafterContext();
 }