Exemplo n.º 1
0
 private async Task <bool> CheckIfCubeExistsAsync(Category category, PlasticColor plasticColor,
                                                  Manufacturer manufacturer, string modelName)
 {
     return((await GetAllCubesAsync()).Any(c => c.Category == category &&
                                           c.PlasticColor == plasticColor && c.Manufacturer == manufacturer &&
                                           c.ModelName == modelName));
 }
Exemplo n.º 2
0
 public RubicsCubePuzzle(string puzzleName, int layers, PlasticColor plasticColor, bool hasMagnets, double height, bool customStickers)
 {
     PuzzleName     = puzzleName;
     Layers         = layers;
     Color          = plasticColor;
     HasMagnets     = hasMagnets;
     CubeHeight     = height;
     CustomStickers = customStickers;
 }
Exemplo n.º 3
0
        public async Task <Result> AddNewCubeAsync(Category category, PlasticColor plasticColor,
                                                   Manufacturer manufacturer, string modelName, int releaseYear, bool permission)
        {
            if (category == null || plasticColor == null || manufacturer == null ||
                string.IsNullOrEmpty(modelName) || (releaseYear < 0 || releaseYear > 2500))
            {
                return(new Result(ApplicationResources.TimerDB.Messages.NullArgument));
            }
            else
            {
                if (await CheckIfCubeExistsAsync(category, plasticColor, manufacturer, modelName))
                {
                    return(new Result(ApplicationResources.TimerDB.Messages.CubeExists));
                }
                else
                {
                    _dbContext.Cubes.Add(new Cube()
                    {
                        Category      = category,
                        PlasticColor  = plasticColor,
                        Manufacturer  = manufacturer,
                        ModelName     = modelName,
                        ReleaseYear   = releaseYear,
                        Rating        = 0.0,
                        RatesAmount   = 0,
                        WcaPermission = permission,
                    });

                    var result = await _dbContext.SaveChangesAsync();

                    if (result == 1)
                    {
                        return(new Result(ApplicationResources.TimerDB.Messages.CubeAddedSuccessfully, false));
                    }

                    return(new Result(ApplicationResources.TimerDB.Messages.CubeAddFailed));
                }
            }
        }
Exemplo n.º 4
0
        public async Task <Result> UpdateCubeAsync(long identity, Category category, PlasticColor plasticColor,
                                                   Manufacturer manufacturer, string modelName, int releaseYear, bool permission)
        {
            var cube = await GetCubeAsync(identity);

            if (cube == null)
            {
                return(new Result(ApplicationResources.TimerDB.Messages.CubeNotExists));
            }
            else
            {
                if (category == null || plasticColor == null || manufacturer == null ||
                    string.IsNullOrEmpty(modelName) || (releaseYear < 0 || releaseYear > 2500))
                {
                    return(new Result(ApplicationResources.TimerDB.Messages.NullArgument));
                }
                else
                {
                    cube.Category      = category;
                    cube.PlasticColor  = plasticColor;
                    cube.Manufacturer  = manufacturer;
                    cube.ModelName     = modelName;
                    cube.ReleaseYear   = releaseYear;
                    cube.WcaPermission = permission;

                    var result = await _dbContext.SaveChangesAsync();

                    if (result == 1)
                    {
                        return(new Result(ApplicationResources.TimerDB.Messages.CubeUpdateSuccessfull, false));
                    }
                    else
                    {
                        return(new Result(ApplicationResources.TimerDB.Messages.CubeUpdateFailed));
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static RubicsCubePuzzle CreatePuzzle(string puzzleName, int layers = 3, PlasticColor color = PlasticColor.BLACK,
                                                    bool hasMagnets = false, double height = 55.7, bool customStickers = false)
        {
            //we can't create puzzle with less than 2 layers because it has no sense
            if (layers < 2)
            {
                throw new ArgumentOutOfRangeException($"Layers must be equal or greater than 2.\n");
            }
            var layersNumber = layers;
            var stickers     = customStickers;

            //if puzzle is stickerless, than it should not have stickers thus customsStickers variable should be false
            //if PlasticColor is not stickerless than it sopposes that puzzle has stickers
            if (color == PlasticColor.STICKERLESS)
            {
                stickers = false;
            }
            return(new RubicsCubePuzzle(puzzleName, layersNumber, color, hasMagnets, height, stickers));
        }