public async Task <IActionResult> CreateUser(FullProfileViewModel viewModel) { var user = _userService.GetUser(); if (viewModel.AvatarFile != null) { var fileExtention = Path.GetExtension(viewModel.AvatarFile.FileName); var fileName = $"{user.Id}{fileExtention}"; var path = Path.Combine( _webHostEnvironment.WebRootPath, "Image", "Avatars", fileName); using (var fileStream = new FileStream(path, FileMode.OpenOrCreate)) { await viewModel.AvatarFile.CopyToAsync(fileStream); } user.AvatarUrl = $"/Image/Avatars/{fileName}"; } user.Age = viewModel.Age; user.Name = viewModel.Name; _citizenRepository.Save(user); return(RedirectToAction("Index")); }
private static void CreateDefaultPolice(IServiceProvider serviceProvider) { IPoliceRepository policeRepository = serviceProvider.GetService <IPoliceRepository>(); ICitizenRepository citizenRepository = serviceProvider.GetService <ICitizenRepository>(); if (!policeRepository.GetAllAsIQueryable().Any()) { if (citizenRepository.GetByName(SHERIFF) == null) { Citizen policeman = new Citizen { Name = SHERIFF, Age = 35, Password = "******" }; citizenRepository.Save(policeman); policeRepository.Save(new Policeman { Citizen = policeman, Rank = Rank.Sheriff, StartWork = DateTime.Now, Salary = 2500 }); } } }
public void Save(LoginViewModel viewModel) { var citizen = new Citizen() { Name = viewModel.Name, Password = viewModel.Password }; _citizenRepository.Save(citizen); }