public async Task <IActionResult> Edit(int id, [Bind("MarinaOwnerId,PersonId")] MarinaOwner marinaOwner)
        {
            if (id != marinaOwner.MarinaOwnerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _marinaOwnerService.Update(marinaOwner);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await _marinaOwnerService.Exists(marinaOwner.MarinaOwnerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            // should get all people, personService??
            var people = await _marinaOwnerService.GetAll();

            ViewData["PersonId"] = new SelectList(people, "PersonId", "Email", marinaOwner.PersonId);
            return(View(marinaOwner));
        }
Beispiel #2
0
        public async Task <int> Create(MarinaOwner marinaOwner)
        {
            marinaOwner.ThrowIfNull();

            await _context.AddAsync(marinaOwner);

            return(marinaOwner.MarinaOwnerId);
        }
        public async Task <IActionResult> Create([Bind("MarinaOwnerId,PersonId")] MarinaOwner marinaOwner)
        {
            if (ModelState.IsValid)
            {
                await _marinaOwnerService.Create(marinaOwner);

                return(RedirectToAction(nameof(Index)));
            }

            // should get all people, personService??
            var people = await _marinaOwnerService.GetAll();

            ViewData["PersonId"] = new SelectList(people, "PersonId", "Email", marinaOwner.PersonId);
            return(View(marinaOwner));
        }
        public async void GetBookingsByMarinOwner_Expected2_Pass()
        {
            using (var context = Fixture.CreateContext())
            {
                bool expected = true;

                IBookingService bookingService = new BookingService(context, null, null, null, null);
                Marina          marina         = context.Marinas.Find(1);
                MarinaOwner     marinaOwner    = context.MarinaOwners.Where(mo => mo.MarinaOwnerId == marina.MarinaOwnerId).FirstOrDefault();
                bool            spotsCreated   = await GenerateBookingData.CreateBookingWithTwoSpotsInSameMarina() != null;

                var marinaOwnerBookings = (List <BookingLine>) await bookingService.GetBookingLines(marinaOwner.MarinaOwnerId);

                bool actual = marinaOwnerBookings == null ? false : marinaOwnerBookings.Count > 0 ? true : false;

                Assert.True(spotsCreated);
                Assert.Equal(expected, actual);
            }
        }
        public async Task <MarinaOwner> MakePersonMarinaOwner(Person person)
        {
            person.ThrowIfNull();

            if (_context.MarinaOwners.AsQueryable().Any(p => p.PersonId.Equals(person.Id)))
            {
                throw new BusinessException("Email", "You are already registered as a marina owner!");
            }

            var marinaOwner = new MarinaOwner {
                PersonId = person.Id
            };

            await _context.MarinaOwners.AddAsync(marinaOwner);

            await AddToRoleAsync(person, RoleName.MarinaOwner);

            return(marinaOwner);
        }
        public async void GetUnconfirmedBookingLines_Pass()
        {
            using (var context = Fixture.CreateContext())
            {
                bool                expected           = true;
                ILocationService    locationService    = new LocationService(context);
                IMarinaService      marinaService      = new MarinaService(context, locationService);
                IBookingFormService bookingFormService = new BookingFormService(context, marinaService);
                IBookingLineService service            = new BookingLineService(context, bookingFormService);
                IMarinaOwnerService marinaOwnerService = new MarinaOwnerService(context, service);
                Marina              marina             = context.Marinas.Find(1);
                MarinaOwner         marinaOwner        = context.MarinaOwners.Where(mo => mo.MarinaOwnerId == marina.MarinaOwnerId).FirstOrDefault();
                bool                spotsCreated       = await GenerateBookingData.CreateBookingWithTwoSpotsInSameMarina() != null;

                var spotsToConfirm = (List <BookingLine>) await marinaOwnerService.GetUnconfirmedBookingLines(marinaOwner.MarinaOwnerId);

                bool actual = spotsToConfirm == null ? false : spotsToConfirm.Count > 0 ? true : false;

                Assert.True(spotsCreated);
                Assert.Equal(expected, actual);
            }
        }
        public static void SeedDb(SportsContext context)
        {
            //TODO: Remove in Release :)
            context.Database.EnsureDeleted();

            context.Database.EnsureCreated();

            //TODO: Add seed data or use NMockaroo

            //Insert data into the database if there aren't any in the specific table
            if (!context.Addresses.Any())
            {
                var addresses = new Address[]
                {
                    new Address {
                        Street = "Amazing Drive", City = "Aalborg", Country = "DK", State = "DK"
                    },
                    new Address {
                        Street = "Not so Amazing Drive", City = "Copenhagen", Country = "DK", State = "DK"
                    },
                    new Address {
                        City = "Aalborg", Street = "Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark"
                    },
                    new Address {
                        City = "Aarhus", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark"
                    },
                    new Address {
                        City = "Copenhagen", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark"
                    },
                    new Address {
                        City = "Esbjerg", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark"
                    },
                };

                context.Addresses.AddRange(addresses);
                context.SaveChanges();
            }

            if (!context.Locations.Any())
            {
                var locations = new Location[]
                {
                    new Location {
                        Latitude = 55.724478044067006, Longitude = 12.60262191295624
                    },
                    new Location {
                        Latitude = 57.058790791383466, Longitude = 9.895803630352022
                    },
                    new Location {
                        Latitude = 57.05889288811736, Longitude = 9.895127713680269
                    },
                };

                context.Locations.AddRange(locations);
                context.SaveChanges();
            }

            if (!context.Persons.Any())
            {
                var persons = new Person[]
                {
                    new Person {
                        FirstName = "Bartosz", LastName = "Urban", Email = "*****@*****.**", AddressId = 1
                    },
                    new Person {
                        FirstName = "Dragos", LastName = "Ionescu", Email = "*****@*****.**", AddressId = 1
                    },
                    new Person {
                        FirstName = "Peter", LastName = "Boelt", Email = "*****@*****.**", AddressId = 2
                    },
                    new Person {
                        FirstName = "Zach", LastName = "Horatau", Email = "*****@*****.**", AddressId = 2
                    }
                };

                context.Persons.AddRange(persons);
                context.SaveChanges();
            }

            if (!context.MarinaOwners.Any())
            {
                var marinaOwners = new MarinaOwner[]
                {
                    new MarinaOwner {
                        PersonId = 1
                    },
                    new MarinaOwner {
                        PersonId = 2
                    },
                    new MarinaOwner {
                        PersonId = 3
                    },
                    new MarinaOwner {
                        PersonId = 4
                    },
                };

                context.MarinaOwners.AddRange(marinaOwners);
                context.SaveChanges();
            }

            if (!context.Marinas.Any())
            {
                var marinas = new Marina[]
                {
                    new Marina {
                        Name = "Aalborg Marina", MarinaOwnerId = 1, Description = "Coolest marina", Facilities = "none", AddressId = 1
                    },
                    new Marina {
                        Name = "Aarhus Marina", MarinaOwnerId = 2, Description = "Some marina", Facilities = "none", AddressId = 2
                    },
                    new Marina {
                        Name = "Copenhagen Marina", MarinaOwnerId = 3, Description = "Some marina", Facilities = "none", AddressId = 3
                    },
                    new Marina {
                        Name = "Esbjerg Marina", MarinaOwnerId = 1, Description = "Some marina", Facilities = "none", AddressId = 4
                    },
                };

                context.Marinas.AddRange(marinas);
                context.SaveChanges();
            }

            if (!context.BoatOwners.Any())
            {
                var boatOwners = new BoatOwner[]
                {
                    new BoatOwner {
                        PersonId = 3
                    },
                    new BoatOwner {
                        PersonId = 4
                    }
                };

                context.BoatOwners.AddRange(boatOwners);
                context.SaveChanges();
            }

            if (!context.Boats.Any())
            {
                var boats = new Boat[]
                {
                    new Boat {
                        Name = "Titanic", BoatOwnerId = 1, Depth = 2, Length = 5, Width = 3
                    },
                    new Boat {
                        Name = "Mama Destroyer", BoatOwnerId = 2, Depth = 5, Length = 20, Width = 9
                    },
                };

                context.Boats.AddRange(boats);
                context.SaveChanges();
            }

            if (!context.Spots.Any())
            {
                var spots = new Spot[]
                {
                    new Spot {
                        SpotNumber = 1, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 10, MaxLength = 30
                    },
                    new Spot {
                        SpotNumber = 2, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30
                    },
                    new Spot {
                        SpotNumber = 3, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30
                    },
                    new Spot {
                        SpotNumber = 4, MarinaId = 2, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 3
                    },
                    new Spot {
                        SpotNumber = 5, MarinaId = 3, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30
                    },
                    new Spot {
                        SpotNumber = 1, MarinaId = 4, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 1
                    },
                    new Spot {
                        SpotNumber = 2, MarinaId = 4, Available = true, Price = 40.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 2
                    },
                    new Spot {
                        SpotNumber = 3, MarinaId = 4, Available = true, Price = 30.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30
                    }
                };

                context.Spots.AddRange(spots);
                context.SaveChanges();
            }

            if (!context.Bookings.Any())
            {
                var bookings = new Booking[]
                {
                    new Booking {
                        BookingReferenceNo = 1, BoatId = 1, TotalPrice = 2, PaymentStatus = "not paid", CreationDate = DateTime.Now
                    },
                    new Booking {
                        BookingReferenceNo = 2, BoatId = 1, TotalPrice = 10, PaymentStatus = "not paid", CreationDate = DateTime.Now
                    },
                    new Booking {
                        BookingReferenceNo = 3, BoatId = 1, TotalPrice = 100, PaymentStatus = "not paid", CreationDate = DateTime.Now
                    },
                    new Booking {
                        BookingReferenceNo = 4, BoatId = 2, TotalPrice = 83, PaymentStatus = "not paid", CreationDate = DateTime.Now
                    },
                    new Booking {
                        BookingReferenceNo = 5, BoatId = 2, TotalPrice = 97, PaymentStatus = "not paid", CreationDate = DateTime.Now
                    },
                    new Booking {
                        BookingReferenceNo = 6, BoatId = 2, TotalPrice = 23, PaymentStatus = "not paid", CreationDate = DateTime.Now
                    }
                };

                context.Bookings.AddRange(bookings);
                context.SaveChanges();
            }

            if (!context.BookingLines.Any())
            {
                var bookingLines = new BookingLine[]
                {
                    // Ongoing: True
                    new BookingLine {
                        Ongoing = true, BookingId = 1, SpotId = 1, DiscountedTotalPrice = 1, Confirmed = true, StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 1, SpotId = 2, DiscountedTotalPrice = 2, StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 1, SpotId = 3, DiscountedTotalPrice = 3, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4)
                    },
                    // Ongoing: False
                    new BookingLine {
                        Ongoing = false, BookingId = 2, SpotId = 1, DiscountedTotalPrice = 4, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 2, SpotId = 2, DiscountedTotalPrice = 5, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 2, SpotId = 3, DiscountedTotalPrice = 6, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7)
                    },
                    // Ongoing: False
                    new BookingLine {
                        Ongoing = false, BookingId = 3, SpotId = 1, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 3, SpotId = 2, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 3, SpotId = 3, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7)
                    },

                    // Ongoing: False
                    new BookingLine {
                        Ongoing = false, BookingId = 4, SpotId = 1, DiscountedTotalPrice = 19, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 4, SpotId = 2, DiscountedTotalPrice = 11, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15)
                    },
                    new BookingLine {
                        Ongoing = false, BookingId = 4, SpotId = 3, DiscountedTotalPrice = 17, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15)
                    },
                    // Ongoing: True
                    new BookingLine {
                        Ongoing = true, BookingId = 5, SpotId = 1, DiscountedTotalPrice = 15, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25)
                    },
                    new BookingLine {
                        Ongoing = true, BookingId = 5, SpotId = 3, DiscountedTotalPrice = 16, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25)
                    },
                    new BookingLine {
                        Ongoing = true, BookingId = 5, SpotId = 2, DiscountedTotalPrice = 14, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25)
                    },
                    // Ongoing: True
                    new BookingLine {
                        Ongoing = false, BookingId = 6, SpotId = 1, DiscountedTotalPrice = 12
                    },
                    new BookingLine {
                        Ongoing = true, BookingId = 6, SpotId = 2, DiscountedTotalPrice = 13
                    },
                    new BookingLine {
                        Ongoing = true, BookingId = 6, SpotId = 5, DiscountedTotalPrice = 14
                    }
                };

                context.BookingLines.AddRange(bookingLines);
                context.SaveChanges();
            }
        }
Beispiel #8
0
 public MarinaOwner Update(MarinaOwner marinaOwner)
 {
     marinaOwner.ThrowIfNull();
     _context.MarinaOwners.Update(marinaOwner);
     return(marinaOwner);
 }