public IActionResult AddUplink( string type, string title, string host, string user, string password) { // Checks if instance already exists. if (model.ProvideInstance("uplink", title) == null) { // Create new uplink model instance and put to global instance register. UplinkModel uplink = new UplinkModel() { Host = host, Title = title, Type = type, User = user, Password = password }; if (model.RegisterInstance("uplink", title, uplink)) { return(new OkResult()); } else { return(new BadRequestResult()); } } else { return(EditUplink(title, null, type, host, -1, user, password)); } }
public IActionResult EditUplink(string title, string newTitle = null, string type = null, string host = null, int port = -1, string user = null, string password = null) { UplinkModel uplink = (UplinkModel)model.ProvideInstance("uplink", title); if (uplink != null) { /* Assign new properties. */ // type if (!String.IsNullOrWhiteSpace(type)) { uplink.Type = type; } // title if (!String.IsNullOrWhiteSpace(newTitle)) { uplink.Title = newTitle; } // host if (!String.IsNullOrWhiteSpace(host)) { uplink.Host = host; } // port if (port != -1) { uplink.Host = new UriBuilder(uplink.Type, uplink.Host, port).Path; } // user if (!String.IsNullOrWhiteSpace(user)) { uplink.User = user; } // password if (!String.IsNullOrWhiteSpace(password)) { uplink.Password = password; } // Register edited uplink and delete old instance. if (model.RemoveInstance(uplink.Type, title)) { model.RegisterInstance(uplink.Type, uplink.Title, uplink); } return(Ok()); } return(BadRequest()); }