public void Database_Delete_PendingAdd() { //arrange var newEvent = new Event { Title = "Sample Event", Description = "Sample Event Description", StartDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddHours(1), RegistrationType = new RegistrationType(), Registrations = new List <Registration>(), EventType = new EventType(), Status = new Status(), LocationInformation = "At some new location", LogoPath = "http://google/someimage", }; //act Context.Events.Add(newEvent); Context.SaveChanges(); Context.DeleteDataFromDbSet(Context.Events); //assert Context.Events.Count().ShouldBe(0); }
public void RemoveCapstone(int id) { Capstone capstone = GetCapstoneById(id); List <Day> days = dayRepository.GetDaysByCapstoneId(id); foreach (Day day in days) { dayRepository.RemoveDay(day.DayId); } _context.Capstones.Remove(capstone); _context.SaveChanges(); }
public void AssignTeams(List <StudentAssignment> data) { // Step 0 - Business Rules: // - The smallest team size is four students // - The largest team size is seven students // - Clients with more than seven students must be broken into separate teams, each with a team letter(starting with 'A'). // - Only assign students to clients that have been confirmed as participating. // Step 1 - OLTP using (var context = new CapstoneContext()) { foreach (var item in data) { var assignment = new TeamAssignment(); assignment.ClientId = item.ClientId; assignment.StudentId = item.StudentId; assignment.TeamNumber = item.TeamLetter; context.TeamAssignments.Add(assignment); } // And... Commit all the changes context.SaveChanges(); // OLTP all done } }
public ActionResult CreateCapstone([Required, FromBody] Capstone capstone, [Required] int UserId) { if (capstone == null) { return(BadRequest("Capstone is null")); } if (CapstoneExists(UserId) && capstone.UserId == UserId) { return(BadRequest("Capstone by this name already exists for this user")); } capstoneRepository.CreateCapstone(capstone); _capstoneContext.SaveChanges(); return(Ok(new { Capstone = capstone })); }
public static void RemoveDbSetDataDatabase(this CapstoneContext context, DbSet set) { var dataDeleter = new DatabaseDataDeleter(context); RemoveDbSetData(set); context.SaveChanges(); dataDeleter.DeleteAllObjects(); }
public void Add_Status_With_Defaults() { //arrange var newStatus = new Status(); //act Context.Statuses.Add(newStatus); Context.SaveChanges(); //assert int rowCount = Context.Statuses.Count(); rowCount.ShouldBeGreaterThan(0); }
public void Add_EventType_With_Defaults() { //arrange var newEventType = new EventType(); //act Context.EventType.Add(newEventType); Context.SaveChanges(); //assert int rowCount = Context.EventType.Count(); rowCount.ShouldBeGreaterThan(0); }
public static void RemoveAllDbSetDataDatabase(this CapstoneContext context) { var dataDeleter = new DatabaseDataDeleter(context); RemoveDbSetData(context.Events); RemoveDbSetData(context.EventType); RemoveDbSetData(context.Category); RemoveDbSetData(context.Registrations); RemoveDbSetData(context.Statuses); context.SaveChanges(); dataDeleter.DeleteAllObjects(); }
public User Create(User user, string password) { if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password is required"); } if (_context.Users.Any(x => x.Email.Equals(user.Email))) { throw new AppException("Email is already in use"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; _context.Users.Add(user); _context.SaveChanges(); return(user); }
public IActionResult Create(PayrollItem pro) { try { pro = _context.PayrollItems.Add(pro).Entity; _context.SaveChanges(); return(Ok(new { Id = pro.Id, Message = "Ok" })); } catch (Exception e) { return(StatusCode(500)); } }
public void Add_Category_With_Defaults() { //arrange var newCategory = new RegistrationType(); //act Context.Category.Add(newCategory); Context.SaveChanges(); //assert int rowCount = Context.Category.Count(); rowCount.ShouldBeGreaterThan(0); }
public void SaveChanges() { _context.SaveChanges(); }
public IActionResult Create() { if (Request.HasFormContentType) { Guid imageId = Guid.NewGuid(); IFormCollection form = Request.Form; string name = form["name"]; string description = form["description"]; DateTime start = Convert.ToDateTime(form["start"]).ToUniversalTime(); DateTime end = Convert.ToDateTime(form["end"]).ToUniversalTime(); int capacity = int.Parse(form["capacity"]); IFormFile image = form.Files.FirstOrDefault(); string fileExtension = String.Empty; User createdBy = _context.Users.Find(Guid.Parse(this.User.Identity.Name)); // Handle upload if (image != null) { // Create directory for uploads string uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); string imageDir = Path.Combine(uploads, imageId.ToString()); if (!Directory.Exists(uploads)) { Directory.CreateDirectory(uploads); } Directory.CreateDirectory(imageDir); // Get file extension fileExtension = Path.GetExtension(image.FileName); Image <Rgba32> resizedImage = imageService.CreateThumbnail(image); Image <Rgba32> heroImage = imageService.CreateHero(image); // Set paths for saving files string uniqueFileName = String.Concat("full", fileExtension); string thumbnailFileName = String.Concat("thumbnail", fileExtension); string heroFileName = String.Concat("hero", fileExtension); string filePath = Path.Combine(imageDir, uniqueFileName); string thumbnailPath = Path.Combine(imageDir, thumbnailFileName); string heroPath = Path.Combine(imageDir, heroFileName); // Save full-size file using (FileStream fileStream = new FileStream(filePath, FileMode.Create)) { image.CopyTo(fileStream); fileStream.Flush(); } // Save thumbnail and hero resizedImage.Save(thumbnailPath); heroImage.Save(heroPath); } Event item = new Event { Name = name, Description = description, Start = start, End = end, Capacity = capacity, ImageId = imageId, ImageExtension = fileExtension, CreatedBy = createdBy }; _context.Events.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetEvent", new Event { Id = item.Id }, item)); } else { return(BadRequest()); } }
public void Add_Event_With_Defaults() { // arrange // act Context.Events.Add(_sampleEvent); Context.SaveChanges(); //assert int rowCount = Context.Events.Count(); rowCount.ShouldBeGreaterThan(0); }
public void Add_Registration_With_Defaults() { //arrange var newEvent = new Event { Title = "Sample Event", Description = "Sample Event Description", StartDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddHours(1), RegistrationType = new RegistrationType(), Registrations = new List <Registration>(), EventType = new EventType(), Status = new Status(), LocationInformation = "At some new location", LogoPath = "http://google/someimage" }; Context.Events.Add(newEvent); var newRegistration = new Registration() { Event = newEvent, EventType = new EventType(), RegisterDateTime = DateTime.Now, Title = "A title" }; //act Context.Registrations.Add(newRegistration); Context.SaveChanges(); //assert int rowCount = Context.Registrations.Count(); rowCount.ShouldBeGreaterThan(0); }
public IActionResult Create(RegistrationDto registrationDto) { PrimaryContact primaryContact = registrationDto.PrimaryContact; Event vmEvent = _context.Events .Where(e => e.Id == registrationDto.Event.Id) .Include(e => e.Registrations) .ThenInclude(r => r.Registrant) .First(); // Add primary contact if necessary if (!_context.PrimaryContacts.Any(pc => pc.Name.Equals(primaryContact.Name) && pc.EmailAddress.Equals(primaryContact.EmailAddress) && pc.PhoneNumber.Equals(primaryContact.PhoneNumber))) { _context.PrimaryContacts.Add(primaryContact); _context.SaveChanges(); } else { primaryContact = _context.PrimaryContacts .Where(pc => pc.Name.Equals(registrationDto.PrimaryContact.Name)) .FirstOrDefault(); } // Iterate over registrants registrationDto.Registrants.ForEach(reg => { Registrant registrant = new Registrant { Name = reg.Name }; bool isWaitList = false; // Add registrant if necessary if (!_context.Registrants.Any(r => r.Name.Equals(registrant.Name))) { _context.Registrants.Add(registrant); _context.SaveChanges(); } else { registrant = _context.Registrants .Where(r => r.Name.Equals(reg.Name)) .FirstOrDefault(); } if (vmEvent.Registrations.Where(r => !r.IsWaitList).Count() >= vmEvent.Capacity) { isWaitList = true; } // Create registration Registration registration = new Registration { Event = vmEvent, PrimaryContact = primaryContact, Registrant = registrant, HasPhotoRelease = reg.PhotoRelease, IsWaitList = isWaitList }; // Add registration if it doesn't already exist if (vmEvent.Registrations == null || vmEvent.Registrations.Count == 0 || !vmEvent.Registrations.Any(r => r.Registrant.Name.Equals(registration.Registrant.Name))) { _context.Registrations.Add(registration); _context.SaveChanges(); } }); return(CreatedAtRoute("GetAll", null)); }