public IActionResult Create(Employee emp) { _dbContext.EMPLOYEE.Add(emp); _dbContext.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// 提交更新 /// </summary> public int Save() { try { return(_context.SaveChanges()); } finally { IsStart = false; } }
/// <summary> /// 新增 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Add <T>(T entity) where T : GenericModel { try { _efCoreContext.Entry(entity).State = EntityState.Added; int rowsAffected = _efCoreContext.SaveChanges(); return(rowsAffected > 0 ? true : false); } catch (Exception ex) { return(false); } }
protected override IDBUpdater DBUpdater => EFCoreDBUpdater.Instance;//new EFCoreDBUpdater(KeyPropertyName); public override void InsertEmptyContact(int recordsCount) { ICustomPermissionPolicyUser currentUser = GetUser(); for (int i = 0; i < recordsCount; i++) { var contact = new Contact() { FirstName = $"Contact{i}" }; ((IContact)contact).SetDepartment(currentUser.Department); dataContext.Contacts.Add(contact); } dataContext.SaveChanges(); }
public override void CleanupTestDataSet() { using (var dataContext = new EFCoreContext()) { dataContext.Entities.RemoveRange(dataContext.Entities.ToList()); dataContext.SaveChanges(); } }
public static void WriteVotesToFile() { if (!SetVotes()) { C.WL("No Data Readable"); return; } var OutputStrings = new string[Votes.Count]; foreach (var vote in Votes) { OutputStrings[Votes.IndexOf(vote)] = vote.Name.PadRight(20) + vote.CampusId + " Exam: " + vote.Exam + " Note: " + vote.Mark; } var session = new Session { ClassVotes = Votes, Date = DateTime.Now }; using (var dbcontext = new EFCoreContext()){//sqlite storage for testing dbcontext.Sessions.Add(session); dbcontext.SaveChanges(); } Program.ProgressBar(); var newFile = FilePath.Replace(Path.GetFileName(FilePath), $"Session{session.Id}.txt"); File.WriteAllLines(newFile, OutputStrings); C.WL("Done !"); reset(); }
public async Task <APIResult> Delete(string guid) { var result = new APIResult(); var user = await db.UserInfo.Where(a => a.GUID == guid).FirstAsync(); if (user == null) { result.Fail("无此记录"); return(result); } db.UserInfo.Remove(user); db.SaveChanges(); result.Success(); return(result); }
public bool InsertCustomer_EntityFramework() { using (var db = new EFCoreContext()) { var id = db.customers.Max(x => x.customerid); var customers = new[] { new Customer { slno = id + 1, customerid = id + 1, firstname = "Prathibha1", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 2, customerid = id + 2, firstname = "Prathibha2", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 3, customerid = id + 3, firstname = "Prathibha3", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 4, customerid = id + 4, firstname = "Prathibha4", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 5, customerid = id + 5, firstname = "Prathibha5", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 6, customerid = id + 6, firstname = "Prathibha6", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 7, customerid = id + 7, firstname = "Prathibha7", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 8, customerid = id + 8, firstname = "Prathibha8", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 9, customerid = id + 9, firstname = "Prathibha9", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 10, customerid = id + 10, firstname = "Prathibha10", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 11, customerid = id + 11, firstname = "Prathibha11", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 12, customerid = id + 12, firstname = "Prathibha12", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 13, customerid = id + 13, firstname = "Prathibha13", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 14, customerid = id + 14, firstname = "Prathibha14", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 15, customerid = id + 15, firstname = "Prathibha15", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, }; db.customers.AddRange(customers); return(db.SaveChanges() >= 0); } }
public Brand Add(Brand model) { using (var db = new EFCoreContext()) { db.Brands.Add(model); db.SaveChanges(); return(model); } }
public Product Add(Product model) { using (var db = new EFCoreContext()) { db.Products.Add(model); db.SaveChanges(); return(model); } }
private static void AddSomeMoreSamurais() { _context.Samurais.AddRange( new Samurais { Name = "Fred" } ); _context.SaveChanges(); }
public Product Update(Product model) { using (var db = new EFCoreContext()) { db.Product.Update(model); db.SaveChanges(); return(model); } }
public Brand Update(Brand model) { using (var db = new EFCoreContext()) { db.Brand.Update(model); db.SaveChanges(); return(model); } }
public Category Update(Category model) { using (var db = new EFCoreContext()) { db.Categories.Update(model); db.SaveChanges(); return(model); } }
public long UpdateDiscreteCustomers(Customer[] customers) { return(Utility.Watch(delegate() { using (var db = new EFCoreContext()) { db.Customers.UpdateRange(customers); db.SaveChanges(); } })); }
public long DeleteDiscreteWarehouses(Warehouse[] warehouses) { return(Utility.Watch(delegate() { using (var db = new EFCoreContext()) { db.Warehouses.RemoveRange(warehouses); db.SaveChanges(); } })); }
public long DeleteDiscreteDetails(OrderDetail[] details) { return(Utility.Watch(delegate() { using (var db = new EFCoreContext()) { db.OrderDetails.RemoveRange(details); db.SaveChanges(); } })); }
public bool UpdateCustomer_EntityFramework() { using (var db = new EFCoreContext()) { for (int id = 40; id <= 55; id++) { var customer = db.customers.Where(x => x.customerid == id).FirstOrDefault(); customer.lastname = "Andy"; } return(db.SaveChanges() >= 0); } }
public bool Delete(T key) { T entity = _dbSet.Find(key); _dbSet.Remove(entity); return(_dbContext.SaveChanges() > 0); }
public bool DeleteCustomer_EntityFramework() { using (var db = new EFCoreContext()) { var maxId = db.customers.Max(x => x.customerid); for (int id = maxId - 100; id <= maxId; id++) { var customer = db.customers.Where(x => x.customerid == id).FirstOrDefault(); db.customers.Remove(customer); } return(db.SaveChanges() >= 0); } }
public Category Update(Category model) { using (var db = new EFCoreContext()) { var category = db.Categories.Find(model.CategoryID); if (category != null) { category.Name = model.Name; db.SaveChanges(); } return(model); } }
public Brand Update(Brand model) { using (var db = new EFCoreContext()) { var brand = db.Brands.Find(model.BrandID); if (brand != null) { brand.Name = model.Name; db.SaveChanges(); } return(model); } }
public bool Delete(int id) { using (var db = new EFCoreContext()) { var model = db.Products.FirstOrDefault(x => x.ID == id); if (model == null) { return(false); } db.Products.Remove(model); db.SaveChanges(); return(true); } }
public long InsertDiscreteProducts(Product[] products) { return(Utility.Watch(delegate() { using (var db = new EFCoreContext()) { foreach (var p in products) { db.Products.Add(p); } db.SaveChanges(); } })); }
public bool Delete(int id) { using (var db = new EFCoreContext()) { var model = db.Categories.FirstOrDefault(q => q.Id == id); if (model == null) { return(false); } db.Categories.Remove(model); db.SaveChanges(); return(true); } }
public override void CreateTestDataSet(int recordsCount) { CleanupTestDataSet(); EFCoreEntity[] data = new EFCoreEntity[recordsCount]; for (int i = 0; i < recordsCount; i++) { data[i] = new EFCoreEntity() { Id = i, Value = i }; } using (var dataContext = new EFCoreContext()) { dataContext.Entities.AddRange(data); dataContext.SaveChanges(); } RecordsCount = recordsCount; }
public Product Update(Product model) { using (var db = new EFCoreContext()) { var product = db.Products.Find(model.ID); if (product != null) { product.BrandID = model.BrandID; product.CategoryID = model.CategoryID; product.Description = model.Description; product.Name = model.Name; db.SaveChanges(); } //db.Products.Update(model); //db.SaveChanges(); return(model); } }
public override void InsertOne(int recordsCount) { using (var transaction = dataContext.Database.BeginTransaction()) { for (int i = 0; i < recordsCount; i++) { var item = new EFCoreEntity() { Id = i, Value = i }; dataContext.Entities.Add(item); dataContext.SaveChanges(); } transaction.Commit(); } }
public bool Register(string username, string password) { using (var db = new EFCoreContext()) { var userList = GetUsers(); foreach (var item in userList) { if (item == username) { return(false); } } var user = new User { Username = username, Password = password }; db.Users.Add(user); db.SaveChanges(); return(true); } }
public ActionResult UpdateProducts() { try { var ID = Convert.ToInt32(Request.Form["ID"].ToString()); var Price = Convert.ToInt32(Request.Form["Price"].ToString()); var products = _context.Products.Find(ID); products.Price = Price; _context.SaveChanges(); return(Ok()); } catch (DbUpdateConcurrencyException) { //if (!ProductsExists(id)) { // return NotFound(); //} //else { // throw; //} return(BadRequest()); } return(NoContent()); }