Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var db     = new MyProjectContext();
            var RedCat = db.RedCat.ToList();

            return(View(RedCat));
        }
Ejemplo n.º 3
0
        protected PageModelBase(MyProjectContext context)
        {
            this.Context  = context;
            this.Username = "******";

            this.RoleName = Role.Anonymous;
            return;
        }
Ejemplo n.º 4
0
 protected HistoryModelBase(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context, contextAccessor)
 {
     this.TableName = typeof(TDomainObject).Name switch
     {
         "Address" => "Addresses",
         "Person" => "Persons",
         _ => "Unknown",
     };
 }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 7
0
 protected IndexModelBase(MyProjectContext context)
 {
     this.Context = context;
 }
Ejemplo n.º 8
0
 public IndexModel(MyProjectContext context) : base(context)
 {
 }
Ejemplo n.º 9
0
 public DeleteModel(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context,
                                                                                           contextAccessor)
 {
 }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
 protected CreateModelBase(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context, contextAccessor)
 {
 }
Ejemplo n.º 12
0
 protected DetailsModelBase(MyProjectContext context, IHttpContextAccessor contextAccessor) : base(context, contextAccessor)
 {
 }
Ejemplo n.º 13
0
 protected ApiControllerBase(MyProjectContext context, IHttpContextAccessor contextAccessor)
 {
     this.Context  = context;
     this.Username = contextAccessor.GetUserName();
 }