protected PageModelBase(MyProjectContext context, IHttpContextAccessor contextAccessor) { this.Context = context; if (contextAccessor == null) { return; } this.Username = contextAccessor.GetUserName(); if (contextAccessor.HttpContext.User.IsInRole(Role.Anonymous)) { this.RoleName = Role.Anonymous; return; } if (contextAccessor.HttpContext.User.IsInRole(Role.User)) { this.RoleName = Role.User; return; } if (contextAccessor.HttpContext.User.IsInRole(Role.Admin)) { this.RoleName = Role.Admin; return; } if (contextAccessor.HttpContext.User.IsInRole(Role.Developer)) { this.RoleName = Role.Developer; return; } }
// GET: /<controller>/ public IActionResult Index() { var db = new MyProjectContext(); var RedCat = db.RedCat.ToList(); return(View(RedCat)); }
protected PageModelBase(MyProjectContext context) { this.Context = context; this.Username = "******"; this.RoleName = Role.Anonymous; return; }
protected HistoryModelBase(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context, contextAccessor) { this.TableName = typeof(TDomainObject).Name switch { "Address" => "Addresses", "Person" => "Persons", _ => "Unknown", }; }
public TeamsController(MyProjectContext context) { _context = context; if (!_context.Team.Any() || !_context.Player.Any()) { DbInitialize.Initialize(_context); } }
public async Task <IActionResult> Edit(MovieModel model, IFormFile fileUpload) { if (model.duration < 1) { ModelState.AddModelError("errDuration", "The duration field is required."); return(View()); } // Set old data db.Movie.Attach(model); MovieModel oldMovie = new MyProjectContext().Movie.Find(model.id); model.coverImg = oldMovie.coverImg; model.createDate = oldMovie.createDate; oldMovie = null; if (ModelState.IsValid) { if (fileUpload != null) { string pathImgMovie = "/image/movie/"; string pathSave = $"wwwroot{pathImgMovie}"; if (!Directory.Exists(pathSave)) { Directory.CreateDirectory(pathSave); } string extFile = Path.GetExtension(fileUpload.FileName); string fileName = DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + extFile; var path = Path.Combine(Directory.GetCurrentDirectory(), pathSave, fileName); using (var stream = new FileStream(path, FileMode.Create)) { await fileUpload.CopyToAsync(stream); } DateTime dateNow = DateTime.Now; model.coverImg = pathImgMovie + fileName; } model.modifyDate = DateTime.Now; db.Entry(model).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
protected IndexModelBase(MyProjectContext context) { this.Context = context; }
public IndexModel(MyProjectContext context) : base(context) { }
public DeleteModel(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context, contextAccessor) { }
public static void Initialize(MyProjectContext context) { context.Database.EnsureCreated(); var team1 = new List <Player>(); var team2 = new List <Player>(); var team3 = new List <Player>(); var team4 = new List <Player>(); List <Player> playersList = new List <Player>() { new Player { Name = "bob" }, new Player { Name = "jens" }, new Player { Name = "malene" }, new Player { Name = "Hans" }, new Player { Name = "Günther" }, new Player { Name = "Manfred" }, new Player { Name = "Gertrud" }, new Player { Name = "Walter" }, new Player { Name = "Wolfgang" }, new Player { Name = "Joachim" }, new Player { Name = "Frank" }, new Player { Name = "Jens" }, new Player { Name = "Mia" }, new Player { Name = "Julian" }, new Player { Name = "bobo" }, new Player { Name = "babo" } }; //context.AddRange(playersList); for (int i = 0; i < 4; i++) { team1.Add(playersList[i]); } for (int i = 4; i < 8; i++) { team2.Add(playersList[i]); } for (int i = 8; i < 12; i++) { team3.Add(playersList[i]); } for (int i = 12; i < 16; i++) { team4.Add(playersList[i]); } context.SaveChanges(); context.AddRange( new Team { TeamName = "holeinone", players = team1 }, new Team { TeamName = "strikeZero", players = team2 }, new Team { TeamName = "DarkenssIncoming", players = team3 }, new Team { TeamName = "LightShade", players = team4 } ); context.SaveChanges(); }
protected CreateModelBase(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context, contextAccessor) { }
protected DetailsModelBase(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context, contextAccessor) { }
protected ApiControllerBase(MyProjectContext context, IHttpContextAccessor contextAccessor) { this.Context = context; this.Username = contextAccessor.GetUserName(); }