Exemple #1
0
        public string GetAllVacantCprNumbers(string testEnvironment)
        {
            var dc = new TestdataToolEntities();

            var CprRow = from result in dc.CprNumbers
                         where result.Environment == testEnvironment && string.IsNullOrEmpty(result.UsedBy)
                         select result;

            var jss = new JavaScriptSerializer();

            return(jss.Serialize(CprRow));
        }
Exemple #2
0
        public string GetCprNumber(string testEnvironment, string reservationId)
        {
            var dc = new TestdataToolEntities();

            tdtWeb.CprNumber cprRow;

            var ReservationIdRequested = !string.IsNullOrEmpty(reservationId);
            var cprRows = dc.CprNumbers.Where(cprNo => cprNo.Environment == testEnvironment);

            cprRow = cprRows.FirstOrDefault();

            if (ReservationIdRequested)
            {
                // find a row matching the reservation
                var matchingCprRows = cprRows.Where(cprNo => cprNo.UsedBy == reservationId);

                // if not found get a unused and reserve that one
                if (matchingCprRows.Count() == 0)
                {
                    cprRow        = cprRows.FirstOrDefault();
                    cprRow.UsedBy = reservationId;
                    dc.SaveChanges();
                }
            }
            else
            {
                // find one that is not reserved
                var matchingCprRows = cprRows.Where(cprNo => cprNo.UsedBy == null);
                cprRow = matchingCprRows.FirstOrDefault();
            }

            // Convert to JSON
            var jss = new JavaScriptSerializer();

            return(jss.Serialize(cprRow));
        }