public IActionResult Post([FromBody] Server server)
        {
            if (server == null)
            {
                return(BadRequest());
            }

            repo.Add(server);

            return(CreatedAtRoute("Get", new { id = server.Id }, server));
        }
Exemple #2
0
        public async Task <IActionResult> Add([FromBody] ServerAddModel inputModel)
        {
            if (inputModel == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            var server = await _serverRepository.Add(inputModel);

            return(Ok(server));
        }
Exemple #3
0
        public async Task <IActionResult> Add([FromBody] ServerAddModel inputModel)
        {
            if (inputModel == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var server = await _serverRepository.Add(inputModel);

                return(Ok(server));
            }
            catch (BadInputException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #4
0
        public async Task <Server> Add(Server server)
        {
            var servers = await _serverRepository.All();

            var jars = await _jarService.GetAll();

            if (servers.Any(s => s.Name == server.Name))
            {
                throw new Exception("The name of the server must be unique.");
            }
            if (jars.All(j => j.Id != server.JarFile))
            {
                throw new Exception("That jar file does not exist.");
            }

            var createdServer = await _serverRepository.Add(server);

            var libServer = _mapper.Map <Server, McWrapperLib.Server>(createdServer);

            libServer.ServerPath  = Path.Combine(ServerPath, libServer.Id.ToString());
            libServer.JarFilePath = await _jarService.GetJarPath(server.JarFile);

            try
            {
                var javaExecutable = (await _mcWrapperRepository.Get("JavaExecutable")).Value;
                libServer.JavaExecutable = javaExecutable;

                var result = ServerManager.CreateServer(libServer);
                if (result)
                {
                    return(createdServer);
                }

                await _serverRepository.Remove(createdServer.Id);

                throw new Exception("ERROR: CONTACT CREATOR OF McWrapper!");
            }
            catch (Exception)
            {
                await _serverRepository.Remove(createdServer.Id);

                throw new Exception("ERROR: There was no JavaExecutable setting found in the database.");
            }
        }
        // TODO handle errors
        private int AddToRepo(ServerResource serverResource)
        {
            var server = new Model.Server
            {
                Name        = serverResource.Name,
                Description = serverResource.Description,
                AuthorId    = userManager.Users.First().Id // TODO current user
            };

            foreach (var link in serverResource.Links.Where(l => l.Rel == LinkTemplates.Servers.GetSimulations.Rel))
            {
                server.AddSimulation(simulationsRepo.Get(link.GetId()));
            }

            foreach (var link in serverResource.Links.Where(l => l.Rel == LinkTemplates.Servers.GetPresentations.Rel))
            {
                server.AddPresentation(presentationsRepo.Get(link.GetId()));
            }

            serversRepo.Add(server);
            return(server.Id);
        }
Exemple #6
0
 public void AddServer(Server server)
 {
     _serverRepoitory.Add(server);
     _unitOfWork.Commit();
 }