Ejemplo n.º 1
0
        public GridMessage SaveGrid(GridDTO gridDTO)
        {
            GridMessage returnGM = new GridMessage();

            try
            {
                Grid updateGrid = _context.Grids.FirstOrDefault(g => g.Id == gridDTO.id);
                if (updateGrid != null)
                {
                    string uniqueId = Guid.NewGuid().ToString();
                    string fileName = $"{uniqueId}.png";
                    string filePath = $"{_webHostEnvironment.ContentRootPath}/wwwroot/Images/{fileName}";

                    updateGrid.Title = fileName;
                    updateGrid.Used  = true;
                    updateGrid.Image = filePath;
                    _context.SaveChanges();
                    _logger.LogDebug($"{REPOSITORY_NAME}.{MethodBase.GetCurrentMethod()}; Updated Grid Saved");

                    byte[] image = Convert.FromBase64String(gridDTO.base64File);
                    File.WriteAllBytes(filePath, image);
                    _logger.LogDebug($"{REPOSITORY_NAME}.{MethodBase.GetCurrentMethod()}; Updated Grid Image File Saved", filePath);

                    returnGM.OperationStatus = true;
                }
            }
            catch (Exception ex)
            {
                _logger.LogDebug($"{REPOSITORY_NAME}.{MethodBase.GetCurrentMethod()}; Error During Operation: {ex.Message}", ex);
            }

            return(returnGM);
        }
Ejemplo n.º 2
0
        public GridBuilder(ISession sess, GridDTO values, string defaultSortFeild)
        {
            sess              = Session;
            Routes            = new RouteDictionary();
            Routes.PageNumber = values.PageNumber;
            Routes.PageSize   = values.PageSize;
            Routes.SortField  = values.SortField;

            SaveRouteSegment();
        }
Ejemplo n.º 3
0
        public PartialViewResult Clues(GridDTO grid)
        {
            var puzzleDto = _puzzleAppService.GetPuzzleFromGrid(grid);
            var words = puzzleDto.Words.MapTo<IList<WordViewModel>>();

            var cluesModel = new CluesViewModel(words);
            //When accessing clues this way, user is always editing the puzzle
            cluesModel.CanEditClues = true;

            return PartialView("_PuzzleClues", cluesModel);
        }
Ejemplo n.º 4
0
        // Used when storing the paging-sorting route segments is necessary
        public GridBuilder(ISession sess, GridDTO values, string defaultSortField)
        {
            session = sess;

            routes               = new RouteDictionary(); //Clears the previous route segment values
            routes.PageNumber    = values.PageNumber;
            routes.PageSize      = values.PageSize;
            routes.SortField     = values.SortField ?? defaultSortField;
            routes.SortDirection = values.SortDirection;

            SaveRouteSegments();
        }
Ejemplo n.º 5
0
        //Constructor to SET the new route data and clear previous route
        public GridBuilder(ISession s, GridDTO values, string defaultSort)
        {
            //Save session
            session = s;

            //Clear any previous route
            grid = new GridDictionary();

            //Inilialize routes
            grid.SortBy        = values.SortBy ?? defaultSort; //If the property Sortby in GridDTO has no value apply the defaultSort field provided in constructor.
            grid.SortDirection = values.SortDirection;
            grid.PageNumber    = values.PageNumber;
            grid.PageSize      = values.PageSize;

            SerializeRoutes();
        }
Ejemplo n.º 6
0
        //Strategy: client side grid is ignorant of words/answers and clue numbers - server works out clue numbers based on grid.
        //Client side clues keep track of the startX and startY of the answers they represent. These are posted to the server (via GridDTO)
        //and the server uses that information to match clues to words in the grid, or determine if/where a new clue needs to be inserted.
        public PuzzleDTO GetPuzzleFromGrid(GridDTO grid)
        {
            //Map the Name, Height, Width etc
            var puzzle = new Puzzle
            {
                Name = grid.Name,
                Width = grid.Width,
                Height = grid.Height
            };

            //Now figure out the Words
            puzzle.Words = new List<Word>();

            //Across
            for (int i = 0; i < grid.Height; i++)
            {
                var gridRow = grid.GridRows[i];
                var words = GetWords(gridRow.SquareContents, true, null, i, grid.Clues);
                foreach (var word in words)
                {
                    puzzle.Words.Add(word);
                }
            }

            //Down
            for (int i = 0; i < grid.Width; i++)
            {
                var squareContents = new List<GridSquareDTO>();
                for (int j = 0; j < grid.Height; j++)
                {
                    var row = grid.GridRows[j];
                    squareContents.Add(row.SquareContents[i]);
                }

                var words = GetWords(squareContents, false, i, null, grid.Clues);
                foreach (var word in words)
                {
                    puzzle.Words.Add(word);
                }
            }

            //Now update the clue numbers (may have changed if user inserted/deleted new word/answer)
            puzzle.UpdateClueNumbers();

            return puzzle.MapTo<PuzzleDTO>();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The List view action handling filtering/sorting for the list.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <returns>The List view</returns>
        public IActionResult List(GridDTO values)
        {
            var builder = new VacationGridBuilder(this.httpCtxAccessor.HttpContext.Session, values, nameof(Vacation.Location.Name));

            var options = new VacationQueryOptions()
            {
                Includes         = "Location, Activities.Activity, Accommodation",
                OrderByDirection = builder.CurrentRoute.SortDirection,
                PageNumber       = builder.CurrentRoute.PageNumber,
                PageSize         = builder.CurrentRoute.PageSize
            };

            options.Sort(builder);

            var vacationViewModel = new VacationListViewModel()
            {
                Vacations    = data.Vacations.List(options),
                CurrentRoute = builder.CurrentRoute,
                TotalPages   = builder.GetTotalPages(data.Vacations.Count)
            };

            return(View(vacationViewModel));
        }
Ejemplo n.º 8
0
        public GridResultDTO Search(string MGLTView)
        {
            string  url          = "http://swapi.co/api/starships/?page=1"; // Need to move to config
            Rest    rest         = new Rest();
            GridDTO starshipsDTO = rest.SendRequestion(url);

            GridResultDTO gridResultDTO = new GridResultDTO();

            if (starshipsDTO == null)
            {
                return(gridResultDTO);
            }

            List <ResultDTO> listResultDTO = new List <ResultDTO>();

            AddResultDTO(MGLTView, listResultDTO, starshipsDTO);

            for (int i = 0; i < Convert.ToInt32(starshipsDTO.Count) / 10; i++)
            {
                if (!string.IsNullOrEmpty(starshipsDTO.Next))
                {
                    starshipsDTO = rest.SendRequestion(starshipsDTO.Next);
                    if (starshipsDTO != null)
                    {
                        AddResultDTO(MGLTView, listResultDTO, starshipsDTO);
                    }
                }
            }

            gridResultDTO.MGLTView  = MGLTView;
            gridResultDTO.Count     = starshipsDTO.Count;
            gridResultDTO.Next      = starshipsDTO.Next;
            gridResultDTO.Previous  = starshipsDTO.Previous;
            gridResultDTO.ResultDTO = listResultDTO;

            return(gridResultDTO);
        }
Ejemplo n.º 9
0
        public List <ResultDTO> AddResultDTO(string MGLTView, List <ResultDTO> listResultDTO, GridDTO starshipsDTO)
        {
            foreach (var item in starshipsDTO.Results)
            {
                ResultDTO resultDTO   = new ResultDTO();
                string    name        = item.Name;
                string    consumables = item.Consumables;
                int       MGLT        = 0;
                int       stops       = 0;
                if (item.MGLT != "unknown")
                {
                    MGLT = Convert.ToInt32(item.MGLT);
                }

                string[] consumablesSplit = consumables.Split(' ');
                if (consumablesSplit.Length == 2 && MGLT != 0)
                {
                    int    consumableNumber = Convert.ToInt32(consumablesSplit[0]); // get the consumables lemits for the the star ship
                    string strTime          = consumablesSplit[1];                  // Get the Start time form consumable
                    int    consumablesDays  = getDays(consumableNumber, strTime);

                    // Calculate Stops
                    //MGLTView /*(distance)*/ / 4 days
                    stops = Convert.ToInt32(Convert.ToInt32(MGLTView) / (consumableNumber * consumablesDays * 24 * MGLT));
                }

                resultDTO.Name  = item.Name;
                resultDTO.Value = stops;
                listResultDTO.Add(resultDTO);
            }

            return(listResultDTO);
        }
Ejemplo n.º 10
0
 public GridMessage SaveGrid(GridDTO grid)
 {
     return(_gridRepository.SaveGrid(grid));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Add in list result
        /// </summary>
        /// <param name="MGLTView"></param>
        /// <param name="listResultDTO"></param>
        /// <param name="starshipsDTO"></param>
        /// <returns>listResultDTO</returns>
        public List <ResultDTO> addResultDTO(string MGLTView, List <ResultDTO> listResultDTO, GridDTO starshipsDTO)
        {
            foreach (var item in starshipsDTO.results)
            {
                ResultDTO resultDTO   = new ResultDTO();
                string    name        = item.name;
                string    consumables = item.consumables;
                int       MGLT        = 0;
                int       stops       = 0;
                if (item.MGLT != "unknown")
                {
                    MGLT = Convert.ToInt32(item.MGLT);
                }

                string[] consumablesSplit = consumables.Split(' ');
                if (consumablesSplit.Length == 2 && MGLT != 0)
                {
                    int    number          = Convert.ToInt32(consumablesSplit[0]);
                    string strTime         = consumablesSplit[1];
                    int    consumablesDays = getDays(number, strTime);

                    stops = Convert.ToInt32(Convert.ToInt32(MGLTView) / (number * consumablesDays * 24 * MGLT));
                }

                resultDTO.name  = item.name;
                resultDTO.value = stops;
                listResultDTO.Add(resultDTO);
            }

            return(listResultDTO);
        }
Ejemplo n.º 12
0
        public ActionResult View(GridDTO grid)
        {
            var puzzleDto = _puzzleAppService.GetPuzzleFromGrid(grid);
            var puzzleModel = puzzleDto.MapTo<PuzzleViewModel>();

            ViewBag.AvailableSizes = _puzzleAppService.GetAvailableSizes();
            return View(puzzleModel);
        }