예제 #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);
        }
예제 #2
0
        public static void Initialize(GridContext context)
        {
            context.Database.EnsureCreated();
            if (context.Grids.Any())
            {
                return;
            }

            for (int i = 0; i < 5000; i++)
            {
                context.Grids.Add(new Grid
                {
                    Order = i,
                    Title = "newimage.png"
                });
            }

            context.SaveChanges();
        }