コード例 #1
0
        public String updateHero([FromBody] Dictionary <string, Object> req)
        {
            DnD5eAPI dnd5eAPI = new DnD5eAPI();
            Races    races    = dnd5eAPI.getRaces();

            if (races == null)
            {
                return("Fail to get races list from dnd5eapi");
            }
            Classes classes = dnd5eAPI.getClasses();

            if (classes == null)
            {
                return("Fail to get classes list from dnd5eapi");
            }

            //erase the retieve data
            dnd5eAPI = null;

            String        json      = JsonConvert.SerializeObject(req, Newtonsoft.Json.Formatting.Indented);
            DataStructure inputData = new DataStructure();

            try
            {
                inputData = JsonConvert.DeserializeObject <DataStructure>(json);
            }
            catch (JsonSerializationException)
            {
                return("incorect input form");
            }

            Validation validation = new Validation();

            validation.setInputData(inputData);
            if (validation.run(races, classes, false) != null)
            {
                return(validation.getErrorMsg());
            }

            DBHandler dBHandler = new DBHandler();

            return(dBHandler.updateChar(inputData));
        }
コード例 #2
0
        public String deleteHero([FromBody] Dictionary <string, string> req)
        {
            String name;

            try {
                name = req["name"];
            }
            catch (KeyNotFoundException) {
                return("DnDBuilder/deleteHero: The key of input json file is incorrect");
            }


            Validation validation = new Validation();
            String     errorMsg   = validation.checkName(name, false);

            if (errorMsg != null)
            {
                return(errorMsg);
            }

            DBHandler dBHandler = new DBHandler();

            return(dBHandler.deleteChar(name));
        }