public bool AddNewPet(Pet pet) { var entry = _ctx.Pets.Add(pet); _ctx.SaveChanges(); return(true); }
public void SaveCreatedItems() { if (_animals == null || _animals.Count <= 0) { var reason = _animals == null ? "null" : "equal or less than zero"; var message = string.Format("Saving business logic was not executed, " + "this was due to the internal list being {0}", reason); throw new PetsEntityException(message); } try { using (PetShopDBContext _dataContext = new PetShopDBContext()) { _dataContext.Animals.AddRange(_animals); _dataContext.SaveChanges(); _animals.Clear(); } } catch (Exception exception) { throw; } }
public void SaveUpdate() { using (PetShopDBContext _dbcontext = new PetShopDBContext()) { if (_currentStock == null) { return; } _dbcontext.Entry(_currentStock).State = EntityState.Modified; _dbcontext.SaveChanges(); } }
private void SaveToDataBase <T>(IList <T> items) { try { using (PetShopDBContext _datacontxt = new PetShopDBContext()) { PersistenceFactory.AssociateWithEntities(_datacontxt, items); _datacontxt.SaveChanges(); } } catch (Exception e) { this.ErrorMessage("Error encountered when trying to load cached data to database.", "Location: SaveToCahcedData :: PersistEntityAsyncro"); this.BackupFailedDatabasePersistence(items); } }
public void SaveCreatedItems() { try { using (PetShopDBContext _dataContext = new PetShopDBContext()) { if (_messages != null && _messages.Count > 0) { _dataContext.Messages.AddRange(_messages); _dataContext.SaveChanges(); _messages.Clear(); } } } catch (Exception exception) { System.Windows.Forms.MessageBox.Show("Problem encountered during persisting Message." + "Message" + exception.Message); } }
public void SaveCreatedItems() { try { using (PetShopDBContext _dbcontext = new PetShopDBContext()) { if (_accounts != null && _accounts.Count > 0) { _dbcontext.Accounts.AddRange(_accounts); _dbcontext.SaveChanges(); _accounts.Clear(); } } } catch (Exception exception) { MessageBox.Show("Problem encountered during persisting account." + "Message" + exception.Message); } }
public void SaveCreatedItems() { try { if (_transactions == null && _transactions.Count <= 0) { return; } using (PetShopDBContext _dbcontext = new PetShopDBContext()) { _dbcontext.Transactions.AddRange(_transactions); _dbcontext.SaveChanges(); _transactions.Clear(); } } catch (Exception exception) { MessageBox.Show("Problem encountered during persisting transaction." + "Message" + exception.Message); } }
public void Create(Category category) { context.Categories.Add(category); context.SaveChanges(); }
public static void TestManyToMay() { using (PetShopDBContext _context = new PetShopDBContext()) { var course = new Course() { NAME = "Customer 111 test 1", SUBJECT_TYPE = "Custimer 111 test", Customers = GetJoinManyToManyCustomer() }; _context.Courses.Add(course); _context.SaveChanges(); } Customer customer; List <Course> courses; var messages = new List <Message>(); using (PetShopDBContext _context = new PetShopDBContext()) { customer = _context.Customers.Find(9162); courses = _context.Courses.ToList(); /*messages = _context.Messages.Where(m => m.SENDER_ID == 9162) * .ToList();*/ } var coursecustomer = courses.Where(c => c.ID < 10).Select(c => new JoinCustomerCourse { CUSTOMER_ID = customer.ID, COURSE_ID = c.ID }).ToList(); customer.Courses = coursecustomer; foreach (var message in messages) { message.MESSAGE_HEAD = "updated messgae"; message.TEXT = "I can now start working on something else"; } using (PetShopDBContext _dbcontext = new PetShopDBContext()) { for (int cycle = 0; cycle < 5; cycle++) { Message message = new Message() { MESSAGE_HEAD = "test message", SENDER = "Need to put id", RECEIVER = "Definitly need to put id", CREATE_DATE = DateTime.Now, SEND_BY_DATE = DateTime.Now, TEXT = "Well i guess i'm making changes to this table next", SENDER_ID = customer.ID }; messages.Add(message); } } customer.Messages = messages; UpdateCustomerClass updateCustomer = new UpdateCustomerClass(customer); updateCustomer.SaveUpdate(); }