public async Task <PhoneBook> CreatePhonebookAsync(string Name) { var phoneBook = new PhoneBook() { Name = Name }; PhoneDB.Add(phoneBook); await Uow.SaveChangesAsync(); return(phoneBook); }
public IActionResult New([Bind("PhoneName,Manufacturer,MSRP,DateReleased,ScreenSize")] Phone newPhone) { newPhone.Id = Guid.NewGuid(); db.Add(newPhone); db.SaveChanges(); return(RedirectToAction("Index")); }
protected override void Up(MigrationBuilder migrationBuilder) { string[] Manufacturers = new string[] { "Samsung", "Apple", "Huawei", "Google", "HTC", "Blu", "Xiaomi", "LeEco", "Sony" }; string[] Models = new string[] { "Xperia", "Redmi Note 3", "Pixel", "Pixel 2", "Pixel XL", "iPhone 7", "iPhone X", "P8", "Mate 9" }; Random rnd = new Random(); Func <float, float, float> GenPrice = (float min, float max) => { return((float)rnd.NextDouble() * (max - min) + min); }; for (int i = 0; i < 100; ++i) { db.Add(new Phone { Id = Guid.NewGuid(), PhoneName = Models[rnd.Next(Models.Length)], Manufacturer = Manufacturers[rnd.Next(Manufacturers.Length)], MSRP = GenPrice(99.99f, 1999.99f), ScreenSize = GenPrice(4.0f, 7.0f), DateReleased = new DateTime(rnd.Next(2012, 2018), rnd.Next(1, 12), rnd.Next(1, 28)) }); } db.SaveChanges(); }
public void SetTempNewPhoneToDBByUserId(long userId) { Phone phone = TempPhone.GetTempNewPhoneByUserId(userId); phone.State = 1; _phoneContext.Add(phone); _phoneContext.SaveChanges(); TempPhone.SetTempNewPhoneByUserId(userId, new Phone()); }
public virtual T Add(T newObj) { if (!CheckConnection()) { return(default(T)); } _context.Add <T>(newObj); _context.SaveChangesAsync().Wait(); return(newObj); }
public PhoneBookUser CreateUser(PhoneBookUser user) { var result = _context.Add(user); _context.SaveChanges(); if (result != null) { return(user); } return(null); }
public async Task <IActionResult> Create( [Bind("Model,Brand,Memory,Rating,Smart,ReleaseDate")] Phone phone) { try { if (ModelState.IsValid) { _context.Add(phone); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(phone)); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(phone)); }