public void SaveUsers(User user) { User user1 = new User(); context.Add(user); context.SaveChanges(); }
public void SaveCityDetails(CityDetailsViewModel cityDetailsViewModel) { try { //string uniqueFileName = null; if (cityDetailsViewModel.Photo != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "Files"); //uniqueFileName = Guid.NewGuid().ToString() + "_" + cityDetailsViewModel.Photo.FileName; string filePath = Path.Combine(uploadsFolder, Guid.NewGuid().ToString() + "_" + cityDetailsViewModel.Photo.FileName); cityDetailsViewModel.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } if (cityDetailsViewModel.StreetsId.Count != 0) { foreach (var streetId in cityDetailsViewModel.StreetsId) { StreetCityDetail streetCityDetail = new StreetCityDetail { CityDetailId = cityDetailsViewModel.CityId, StreetId = streetId }; context.StreetCityDetails.Add(streetCityDetail); } } CityDetail cityDetail = new CityDetail { FullName = cityDetailsViewModel.UserFulName, HomeNumber = cityDetailsViewModel.HomeNumber, FileName = cityDetailsViewModel.Photo.FileName, BirthDate = cityDetailsViewModel.UserBirthDate, CityId = cityDetailsViewModel.CityId }; context.CityDetails.Add(cityDetail); context.SaveChanges(); } catch (Exception ex) { string exception = ex.ToString(); } }