public IActionResult Add(ViewModel assign) { Assignment assignment = assign.Assignment; if (assign.SelectedTags != null) { int id = assign.SelectedTags.ElementAt(0); for (int i = 0; i < assign.SelectedTags.Count(); i++) { AssignmentTag assignmentTag = new AssignmentTag { Assignment = assignment, AssignmentId = assign.Assignment.Id, Tag = _context.Tags.Single(n => n.Id == assign.SelectedTags.ElementAt(i)), TagId = assign.SelectedTags.ElementAt(i) }; _context.AssignmentTags.Add(assignmentTag); } } _context.Add(assignment); _context.SaveChanges(); return(RedirectToAction("Index")); }
public static void MockCustomer(AssignmentDbContext assignmentDbContext) { var customer1 = new Customer() { Name = "Customer1", Email = "*****@*****.**", Phone = 71234568, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; var customer2 = new Customer() { Name = "Customer2", Email = "*****@*****.**", Phone = 234567189, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; var customer3 = new Customer() { Name = "Customer3", Email = "*****@*****.**", Phone = 1239874, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; assignmentDbContext.Add(customer1); assignmentDbContext.Add(customer2); assignmentDbContext.Add(customer3); assignmentDbContext.SaveChanges(); }
public async Task <IActionResult> Create(AssignmentItem model) { if (ModelState.IsValid) { _db.Add(model); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Tag tag) { if (ModelState.IsValid) { _context.Add(tag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tag)); }
public async Task <IActionResult> Create(string classes) { if (ModelState.IsValid) { char[] delimiterChars = { ' ', ',' }; string[] words = classes.Split(delimiterChars, System.StringSplitOptions.RemoveEmptyEntries); foreach (var word in words) { Class newClass = new Class(word); _context.Add(newClass); } await _context.SaveChangesAsync(); return(RedirectToAction("Added")); } return(View()); }
public static void MockTransaction(AssignmentDbContext assignmentDbContext) { var customer = assignmentDbContext.Customers.Select(c => c); var transaction1OfCustomer1 = new Transaction() { Currency = "USD", Amount = (decimal)39.75, Status = StatusTransaction.Success, CustomerId = customer.First().Id, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Date = DateTime.Now }; var transaction2OfCustomer1 = new Transaction() { Currency = "EUR", Amount = (decimal)40.17, Status = StatusTransaction.Canceled, CustomerId = customer.First().Id, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Date = DateTime.Now }; var transaction3OfCustomer1 = new Transaction() { Currency = "THB", Amount = (decimal)150.15, Status = StatusTransaction.Failed, CustomerId = customer.First().Id, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Date = DateTime.Now }; var transaction1OfCustomer2 = new Transaction() { Currency = "JYP", Amount = (decimal)60, Status = StatusTransaction.Success, CustomerId = customer.Last().Id, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Date = DateTime.Now }; var transaction2OfCustomer2 = new Transaction() { Currency = "GBP", Amount = (decimal)48.95, Status = StatusTransaction.Canceled, CustomerId = customer.Last().Id, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Date = DateTime.Now }; var transaction3OfCustomer2 = new Transaction() { Currency = "CNY", Amount = (decimal)7985.07, Status = StatusTransaction.Failed, CustomerId = customer.Last().Id, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Date = DateTime.Now }; assignmentDbContext.Add(transaction1OfCustomer1); assignmentDbContext.Add(transaction2OfCustomer1); assignmentDbContext.Add(transaction3OfCustomer1); assignmentDbContext.Add(transaction1OfCustomer2); assignmentDbContext.Add(transaction2OfCustomer2); assignmentDbContext.Add(transaction3OfCustomer2); assignmentDbContext.SaveChanges(); }