Ejemplo n.º 1
0
        public void Create(Room room)
        {
            var roomList = GetAllByNumber().OrderBy(x => x.RoomNo).ToList();

            for (int i = 0; i < roomList.Count(); i++)
            {
                if (roomList[i].RoomNo == room.RoomNo)
                {
                    throw new DataException($"Room {room.RoomNo}, Already Exsists");
                }
            }
            if (room.RoomType == RoomType.FamilyRoom && room.MaxNoOfCatsInRoom > 4 || room.RoomType == RoomType.StandardRoom && room.MaxNoOfCatsInRoom > 2)
            {
                throw new DataException("Family room can hold a maximum of 4 cats at a time and standard rooms can hold maximum of 2 cats.");
            }
            else
            {
                room.CheckedIn    = false;
                room.CheckedOut   = false;
                room.BookingEnd   = DateTime.Now;
                room.BookingStart = DateTime.Now;
                room.Booked       = false;
                room.Available    = true;
                room.ID           = Guid.NewGuid();
                _context.Add(room);
                _context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public static void Initialize(CatContext context)
        {
            context.Database.EnsureCreated();

            if (context.cats.Any())
            {
                return;
            }

            var cats = new Cat[]
            {
                new Cat {
                    Name = "MeowMeow1", Color = "Caucasian", Price = 400, FavoriteDish = "Tuna", Birthdate = DateTime.Today
                },
                new Cat {
                    Name = "MeowMeow2", Color = "AfricanAmerican", Price = 500, FavoriteDish = "Tuna", Birthdate = DateTime.Today
                },
                new Cat {
                    Name = "MeowMeow3", Color = "Asian", Price = 450, FavoriteDish = "Tuna", Birthdate = DateTime.Today
                }
            };

            foreach (Cat p in cats)
            {
                context.Add(p);
            }
            context.SaveChanges();
        }