示例#1
0
 public void SetGamblerData(GamblerViewModel gambler)
 {
     Gambler.Id          = gambler.Id;
     Gambler.DisplayName = gambler.DisplayName;
     Gambler.UserName    = gambler.UserName;
     Gambler.Roles       = gambler.Roles;
     Gambler.IsAdmin     = gambler.IsAdmin;
 }
示例#2
0
        public string UploadedFile(GamblerViewModel model)
        {
            string uniqueFileName = null;

            if (model.ProfilePictureVM != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.ProfilePictureVM.FileName);
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ProfilePictureVM.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
示例#3
0
        public async Task <IActionResult> Create(GamblerViewModel model)
        {
            if (ModelState.IsValid)
            {
                string  uniqueFileName1 = UploadedFile(model);
                string  uniqueFileName2 = UploadedFile2(model);
                Gambler gambler         = new Gambler
                {
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    FullName       = model.FirstName + " " + model.LastName,
                    Nationality    = model.Nationality,
                    Earnings       = 0,
                    ProfilePicture = uniqueFileName1,
                    CoverPhoto     = uniqueFileName2,
                };
                dbContext.Add(gambler);
                await dbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
示例#4
0
 public static bool IsAdmin(this GamblerViewModel model)
 {
     return(model != null && model.Roles != null && model.Roles.Contains("Admin"));
 }