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; }
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); }
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()); }
public static bool IsAdmin(this GamblerViewModel model) { return(model != null && model.Roles != null && model.Roles.Contains("Admin")); }